给一个词典,找出其中所有最长的单词。
样例
在词典
{
"dog",
"google",
"facebook",
"internationalization",
"blabla"
}
中, 最长的单词集合为 ["internationalization"]
在词典
{
"like",
"love",
"hate",
"yes"
}
中,最长的单词集合为 ["like", "love", "hate"]
-------------------------------------------------------------------------
class Solution:
# @param dictionary: a list of strings
# @return: a list of strings
def longestWords(self, dictionary):
# write your code here
l = []
result = []
for i in dictionary:
l.append(len(i))
l.sort()
maxlen = l[len(l) - 1]
# @param dictionary: a list of strings
# @return: a list of strings
def longestWords(self, dictionary):
# write your code here
l = []
result = []
for i in dictionary:
l.append(len(i))
l.sort()
maxlen = l[len(l) - 1]
for i in dictionary:
if len(i) == maxlen:
result.append(i)
if len(i) == maxlen:
result.append(i)