Created
December 28, 2019 02:31
-
-
Save luoheng23/caafac95df18bd1d955afe16312eb9be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def longestWord(self, words: List[str]) -> str: | |
""" | |
:type words: List[str] | |
:rtype: str | |
""" | |
words.sort() | |
save = set() #用list存储的话,后面搜索会比较慢 | |
res = "" | |
for word in words: | |
if word[:-1] in save or word[:-1] == '': #单字母的单词 word[:-1] == '' | |
if len(word) > len(res): | |
res = word | |
save.add(word) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment