본문 바로가기
알고리즘/leetcode

953. Verifying an Alien Dictionary

by 유이얼 2022. 9. 15.
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) 변환

'알고리즘 > leetcode' 카테고리의 다른 글

1588. Sum of All Odd Length Subarrays  (0) 2022.09.13
496. Next Greater Element I  (0) 2022.09.13
57. Insert Interval  (0) 2022.09.01
16. 3Sum Closest  (0) 2022.08.28
417. Pacific Atlantic Water Flow  (0) 2022.08.26