Posted on

Description

Submission

class Solution {
public:
    bool isAlienSorted(vector<string>& words, string order) {
        map<char, char> Map;
        for(int i = 0; i < 26; ++i) {
            Map[order[i]] = 'a' + i;
        }
        
        vector<string> newWords;
        for(auto& word: words) {
            string t = "";
            for(auto c: word) {
                t.push_back(Map[c]);
            }
            newWords.push_back(t);
        }
        
        for(int i = 1; i < words.size(); ++i) {
            if(newWords[i-1] > newWords[i]) return false;
        }
        
        return true;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *