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())
相关推荐
szial8 分钟前
网络爬虫与 CDP 实战(一):网页数据到底在哪?从 HTTP 到分页采集
网络·爬虫·python·网络爬虫
DanCheng-studio34 分钟前
智能科学与技术毕设易上手题目建议
python·毕业设计·毕设
醇氧37 分钟前
nohup 后台启动 uvicorn(仅测试 / 临时运行)
linux·运维·网络·python·python3.11
All for pursuit.1 小时前
【贪心-2】253.会议室 II
数据结构·c++·算法·leetcode
2601_957883841 小时前
2026年9月:专业解决雷神笔记本维修难题
python·电脑
Omics Pro2 小时前
预测性虚拟细胞中显式机理算子
大数据·数据库·人工智能·python·算法·机器学习·自然语言处理
秋名RG2 小时前
Java历代LTS版本新特性详解(代码增强版)
java·开发语言·python
27669582922 小时前
youdao/有道翻译APP 算法协议分析
开发语言·前端·python·sign·youdao·有道翻译app算法·有道app协议请求
夏天拐跑了西瓜10 小时前
一文入门LangChain:从框架认知到构建你的第一个AI Agent
python·langchain·conda·agent
魔猴疯猿10 小时前
从0到1用Python开发第一个智能体
人工智能·python·深度学习·神经网络·机器学习