알고리즘/leetcode
953. Verifying an Alien Dictionary
유이얼
2022. 9. 15. 02:12
class Solution {
public:
bool isAlienSorted(vector<string>& words, string order) {
int mapping[26];
for (int i = 0; i < 26; ++i)
mapping[order[i] - 'a'] = i;
for (auto& w : words) {
for (auto& c : w) {
c = mapping[c - 'a'];
}
}
return is_sorted(words.begin(), words.end());
}
};
특수한 order를 일반적인 order로(integer order) 변환