Untitled
unknown
plain_text
2 years ago
1.2 kB
5
Indexable
class Solution { public: bool isAlienSorted(vector<string>& words, string order) { unordered_map<char,int>m; int i=1; int n=order.length(); for(auto position:order){ m[position]=n; n--; } for(int x=0;x<words.size()-1;x++){ //if(words[x].length()<=words[x+1].length()){ for(int i=0;i<words.size();i++){ for(int j=0;j<words[x].length();j++){ if(words[i][j]==words[i+1][j]){ if(words[i]==words[i+1]){ return true; } continue; } else if(m[words[i][j]]<m[words[i+1][j]]){ return false; } else if(j==words[x+1].length()){ return false; } else{ return true; } } } //} } return false; } };
Editor is loading...