1. 程式人生 > >Leetcode-953 Verifying an Alien Dictionary(驗證外星語詞典)

Leetcode-953 Verifying an Alien Dictionary(驗證外星語詞典)

 1 string ooder;
 2 bool cmp(const string &a,const string &b)
 3 {
 4     for(int i = 0;i < min(a.size(),b.size());i ++)
 5     {
 6         if(a[i]!=b[i])
 7         {
 8             for(int j = 0;j < ooder.size();j ++)
 9             {
10                 if(ooder[j]==a[i])
11                     return
1; 12 else if(ooder[j]==b[i]) 13 return 0; 14 } 15 } 16 } 17 return a.size()<b.size(); 18 } 19 20 class Solution 21 { 22 public: 23 bool isAlienSorted(vector<string>& words, string order) 24 {
25 vector<string> words2 = words; 26 ooder = order; 27 sort(words.begin(),words.end(),cmp); 28 for(int i = 0;i < words2.size();i ++) 29 { 30 if(words[i]!=words2[i]) 31 return false; 32 }
33 return true; 34 } 35 };