LeetCode刷题(16)
来源:互联网 发布:手机下载网络设置 编辑:程序博客网 时间:2024/05/15 23:50
Group Anagrams
将使用了相同字母的单词分组
字典不支持使用list作为key,原因如链接:list不能作为dict的key于是选择使用元组
class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ dicts = {} for str in strs: key = tuple(sorted(str)) if not dicts.has_key(key): dicts[key] = [] dicts[key].append(str) return dicts.values()
阅读全文
0 0
- LeetCode刷题(16)
- 【leetcode】leetcode 刷题 笔记 (不定期更新)
- leetcode刷题(Python)
- LeetCode刷题(1)
- LeetCode刷题(2)
- LeetCode刷题(3)
- LeetCode刷题(废弃)
- LeetCode刷题(FizzBuzz)
- Leetcode刷题(1)
- Leetcode刷题(2)
- Leetcode刷题(3)
- Leetcode刷题(4)
- Leetcode刷题(5)
- Leetcode刷题(6)
- Leetcode刷题(7)
- Leetcode刷题(13)
- Leetcode刷题(17)
- LeetCode刷题(18)
- 分布式服务框架Dubbo+Zookeeper
- GitHub客户端操作3--pull Request(拉请求)
- zb的生日
- LeetCode 53. Maximum Subarray
- D3D11笔记——Resource基本概念
- LeetCode刷题(16)
- 模板与泛型编程
- 大数据就在我们的日常生活中
- 【Maven】资料库说明
- 任学堂:原来,高手都是这样学会编程的
- 094: 复习习题 型四:左右极限; 型五:连续与间断 ;第二章导数与微分
- 实验3.3 栈与队列——顺序队列
- 信号量与PV操作
- 线性表的应用——多项式的计算