We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 94e5ade commit 5bd1454Copy full SHA for 5bd1454
solution/0953.Verifying an Alien Dictionary/Solution.cpp
@@ -0,0 +1,35 @@
1
+class Solution {
2
+private:
3
+ int ala[26] = {0, } ;
4
+public:
5
+ bool isAlienSorted(vector<string>& words, string order)
6
+ {
7
+ if (words.size() <= 1)
8
+ return true ;
9
+
10
+ int i = 0 ;
11
+ for (i = 0; i < order.size(); ++i)
12
+ ala[order[i] - 'a'] = i ;
13
14
+ for (i = 1; i < words.size(); ++i)
15
+ if (!cmp(words[i-1], words[i]))
16
+ return false ;
17
18
19
+ }
20
21
+ bool cmp(string a, string b)
22
23
+ int i, len = min(a.size(), b.size()) ;
24
+ for (i = 0; i < len; ++i)
25
26
+ int c = ala[ a[i] - 'a' ] - ala[ b[i] - 'a' ] ;
27
+ if (c < 0)
28
29
+ else if (c > 0)
30
31
32
33
+ return i == a.size() ;
34
35
+};
0 commit comments