lintcode python 代码 133 最长单词
2017-06-15 11:08
399 查看
给一个词典,找出其中所有最长的单词。
思路:统计每个单词长度,输出最长的单词。
思路:统计每个单词长度,输出最长的单词。
class Solution: # @param dictionary: a list of strings # @return: a list of strings def longestWords(self, dictionary): # write your code here m = len(dictionary) result = [] if m == 0: return result dictlen = len(dictionary[0]) result.append(dictionary[0]) for d in range(1, m): tmp = dictionary[d] if len(tmp) == dictlen: result.append(tmp) elif len(tmp) > dictlen: result = [] dictlen = len(tmp) result.append(tmp) return result
相关文章推荐
- lintcode-133-最长单词
- LintCode_133_最长单词
- lintCode(133)——最长单词
- LintCode 133 最长单词
- 统计英文单词的个数的python代码
- Python实现统计英文单词个数及字符串分割代码
- lintcode:最长单词
- [Lintcode 397] 最长上升连续子序列(Python)
- 布同 统计英文单词的个数的python代码
- [LintCode 124] 最长连续序列(Python)
- lintcode python代码 422 最后一个单词长度
- lintcode python代码 433岛屿个数
- [LintCode 200] 最长回文字符串(Python)
- 一行Python代码——单词逆转
- lintcode python代码 420 报数
- lintcode python 代码 514 栅栏染色
- <Think Python>中统计文献单词的处理代码
- Python 获取最长单词的两种方法
- lintcode python 代码 514 栅栏染色
- [LintCode 78] 最长公共前缀(Python)