Skip to content

Commit 4f1b2c5

Browse files
committed
LeetCode: 953 solved
1 parent b5c39e8 commit 4f1b2c5

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+
# https://leetcode.com/problems/verifying-an-alien-dictionary/
2+
3+
class Solution:
4+
def isAlienSorted(self, words: [str], order: str) -> bool:
5+
m = {}
6+
for i, o in enumerate(order):
7+
m[o] = i
8+
9+
def is_sorted(w1, w2):
10+
for c1, c2 in zip(w1, w2):
11+
if m[c1] == m[c2]:
12+
continue
13+
return m[c1] < m[c2]
14+
15+
return len(w1) <= len(w2)
16+
17+
for i in range(len(words) - 1):
18+
w1 = words[i]
19+
w2 = words[i + 1]
20+
21+
if not is_sorted(w1, w2):
22+
return False
23+
24+
return True

0 commit comments

Comments
 (0)