0953.cpp (390B)
1 class Solution { 2 public: 3 bool isAlienSorted(vector<string> &words, string order) { 4 vector<char> um(26); 5 for (int i = 0; i < order.size(); i++) 6 um[order[i] - 'a'] = 'a' + i; 7 for (string &word : words) 8 for_each(word.begin(), word.end(), [&um](char &c) { c = um[c - 'a']; }); 9 return is_sorted(words.begin(), words.end()); 10 } 11 };