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())
相关推荐
滴滴滴嘟嘟嘟.2 分钟前
强化学习消融实验-batch_size / clip_range / gae_lambda / lr
python·机器学习
2601_9639329810 分钟前
怀孕四个月能做流产吗?中期妊娠终止方式与子宫修护科普指南
python
zhr_math_king13 分钟前
LangGraph-快速入门-第一个例子
python·langchain
爱吃苹果的梨叔1 小时前
2026年指挥中心分布式坐席怎么选?清虹创智让多系统、多坐席和大屏真正协同
python
起予者汝也1 小时前
Python 数据结构
开发语言·数据结构·python
LadenKiller1 小时前
2026年量化工具增量,放回回测模拟实盘阶段判断
人工智能·python
石一峰6992 小时前
驱动:私有数据为什么要在三个地方各挂一遍?
数据库·python·算法
2601_956319882 小时前
最新量化软件怎么选,先按能力短板匹配工具类型
人工智能·python
Tbisnic2 小时前
26.AI大模型:RNN、LSTM、GRU
人工智能·python·rnn·gru·大模型·llm·lstm
七夜zippoe2 小时前
OpenClaw 实战:智能文档助手——从问答到生成的完整方案
人工智能·python·机器学习·openclaw·智能文档