Skip to content

Commit

Permalink
Update alien-dictionary.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Nov 26, 2016
1 parent d608aa1 commit b9ebbc9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Python/alien-dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def alienOrder(self, words):
nodes.add(c)

for i in xrange(1, len(words)):
if len(words[i-1]) > len(words[i]) and \
words[i-1][:len(words[i])] == words[i]:
return ""
self.findEdges(words[i - 1], words[i], in_degree, out_degree)

for node in nodes:
Expand Down Expand Up @@ -68,6 +71,9 @@ def alienOrder(self, words):
for node in nodes:
ancestors[node] = []
for i in xrange(1, len(words)):
if len(words[i-1]) > len(words[i]) and \
words[i-1][:len(words[i])] == words[i]:
return ""
self.findEdges(words[i - 1], words[i], ancestors)

# Output topological order by DFS.
Expand Down

0 comments on commit b9ebbc9

Please sign in to comment.