首页 > 其他 > 详细

Leetcode-953 Verifying an Alien Dictionary(验证外星语词典)

时间:2018-12-09 13:25:51      阅读:274      评论:0      收藏:0      [点我收藏+]
 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 };

 

Leetcode-953 Verifying an Alien Dictionary(验证外星语词典)

原文:https://www.cnblogs.com/Asurudo/p/10090739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!