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())
相关推荐
testtraveler1 小时前
[Fix] ImportError: libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent
pytorch·python·bug
lang201509281 小时前
Kafka延迟操作机制深度解析
分布式·python·kafka
测试老哥2 小时前
软件测试:测试用例的设计
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
koo3643 小时前
pytorch环境配置
人工智能·pytorch·python
yagamiraito_6 小时前
757. 设置交集大小至少为2 (leetcode每日一题)
算法·leetcode·go
程序员杰哥6 小时前
Python自动化测试之线上流量回放:录制、打标、压测与平台选择
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·压力测试
吴佳浩6 小时前
LangChain v1 重大更新讲解⚠⚠⚠
python·langchain·agent
无敌最俊朗@6 小时前
力扣hot100-141.环形链表
算法·leetcode·链表
顾安r8 小时前
11.20 开源APP
服务器·前端·javascript·python·css3
萧鼎9 小时前
Python PyTesseract OCR :从基础到项目实战
开发语言·python·ocr