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 9d8d185 commit 4f3be67Copy full SHA for 4f3be67
953. Verifying an Alien Dictionary
@@ -0,0 +1,33 @@
1
+class Solution {
2
+ public boolean isAlienSorted(String[] words, String order) {
3
+ int[] mapping = new int[26];
4
+ int seq=0;
5
+ for(char ch:order.toCharArray()){
6
+ mapping[ch-'a'] = seq++;
7
+ }
8
+
9
+ for(int i=0;i<words.length - 1;i++){
10
+ String curr = words[i];
11
+ String next = words[i+1];
12
13
+ int len = Math.min(curr.length(),next.length());
14
15
+ if(len!= curr.length() && len == next.length() && curr.startsWith(next)){
16
+ return false;
17
18
19
+ for(int l=0;l<len;l++){
20
+ if(mapping[curr.charAt(l)-'a'] > mapping[next.charAt(l)-'a']){
21
22
23
24
+ if(mapping[curr.charAt(l)-'a'] < mapping[next.charAt(l)-'a']){
25
+ break;
26
27
28
29
30
31
+ return true;
32
33
+}
0 commit comments