Skip to content

Commit 6607ca3

Browse files
authored
Merge pull request doocs#137 from ashwek/master
0953 Verifying an Alien Dictionary - Python
2 parents 0f6386d + e82d5f8 commit 6607ca3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def isAlienSorted(self, words, order):
3+
"""
4+
:type words: List[str]
5+
:type order: str
6+
:rtype: bool
7+
"""
8+
9+
order = {a: d for d, a in enumerate(order)}
10+
11+
for i in range(1, len(words)):
12+
j = 0
13+
while len(words[i - 1]) > j < len(words[i]):
14+
15+
value = order[words[i - 1][j]] - order[words[i][j]]
16+
17+
if value < 0:
18+
break
19+
elif value > 0 or (j + 1) == len(words[i]):
20+
return False
21+
22+
j += 1
23+
24+
return True

0 commit comments

Comments
 (0)