Python | Leetcode Python题解之第49题字母异位词分组

题目:

题解:

python 复制代码
class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        mp = collections.defaultdict(list)

        for st in strs:
            counts = [0] * 26
            for ch in st:
                counts[ord(ch) - ord("a")] += 1
            # 需要将 list 转换成 tuple 才能进行哈希
            mp[tuple(counts)].append(st)
        
        return list(mp.values())
相关推荐
tjjucheng3 小时前
靠谱的小程序定制开发哪个好
python
num_killer3 小时前
小白的Langchain学习
java·python·学习·langchain
WangYaolove13143 小时前
基于深度学习的中文情感分析系统(源码+文档)
python·深度学习·django·毕业设计·源码
自学不成才4 小时前
深度复盘:一次flutter应用基于内存取证的黑盒加密破解实录并完善算法推理助手
c++·python·算法·数据挖掘
June`5 小时前
全排列与子集算法精解
算法·leetcode·深度优先
徐先生 @_@|||5 小时前
Palantir Foundry 五层架构模型详解
开发语言·python·深度学习·算法·机器学习·架构
深蓝电商API6 小时前
Scrapy爬虫限速与并发控制最佳实践
爬虫·python·scrapy
Derrick__16 小时前
淘宝MD5爬虫
爬虫·python
薛定谔的猫19826 小时前
llama-index Embedding 落地到 RAG 系统
开发语言·人工智能·python·llama-index
夏鹏今天学习了吗6 小时前
【LeetCode热题100(78/100)】爬楼梯
算法·leetcode·职场和发展