Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created August 12, 2018 10:24
Show Gist options
  • Save luojiyin1987/5215693b0dfe32605c7ba527b6a23a94 to your computer and use it in GitHub Desktop.
Save luojiyin1987/5215693b0dfe32605c7ba527b6a23a94 to your computer and use it in GitHub Desktop.
Longest Word in Dictionary
class Solution(object):
def longestWord(self, words):
"""
:type words: List[str]
:rtype: str
"""
wSet =set([''])
ans = ''
for word in sorted(words):
if word[:-1] in wSet:
wSet.add(word)
if len(word) > len(ans):
ans = word
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment