Skip to content

Commit 341399d

Browse files
committed
953 - Solution.py
1 parent 3161697 commit 341399d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
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)