GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/python/953_Verifying_an_Alien_Dictionary.py at master · qiyuangong/leetcode

Expand file tree

/

953_Verifying_an_Alien_Dictionary.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
32 lines (29 loc) · 1008 Bytes
/

953_Verifying_an_Alien_Dictionary.py

Copy path

File metadata and controls

32 lines (29 loc) · 1008 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution(object):
def isAlienSorted(self, words, order):
"""
:type words: List[str]
:type order: str
:rtype: bool
"""
order_map = {}
for i, v in enumerate(order):
order_map[v] = i
def cmp_alien(x, y):
ls = min(len(x), len(y))
index = 0
while index < ls:
if x[index] != y[index]:
return order_map[x[index]] - order_map[y[index]]
index += 1
return len(x) - len(y)
pos = 0
while pos + 1 < len(words):
if cmp_alien(words[pos], words[pos + 1]) > 0:
return False
pos += 1
return True
if __name__ == '__main__':
s = Solution()
print s.isAlienSorted(["hello","leetcode"], "hlabcdefgijkmnopqrstuvwxyz")
print s.isAlienSorted(["word","world","row"], "worldabcefghijkmnpqstuvxyz")
print s.isAlienSorted(["apple","app"], "abcdefghijklmnopqrstuvwxyz")
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.