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())
相关推荐
资深web全栈开发8 小时前
LeetCode 3623. 统计梯形的数目 I
算法·leetcode·职场和发展·组合数学
Wise玩转AI15 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
s***469816 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
云里雾里!16 小时前
力扣 209. 长度最小的子数组:滑动窗口解法完整解析
数据结构·算法·leetcode
runepic16 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
codists16 小时前
2025年11月文章一览
python
生而为虫16 小时前
31.Python语言进阶
python·scrapy·django·flask·fastapi·pygame·tornado
言之。17 小时前
Claude Code 实用开发手册
python
计算机毕设小月哥17 小时前
【Hadoop+Spark+python毕设】中国租房信息可视化分析系统、计算机毕业设计、包括数据爬取、Spark、数据分析、数据可视化、Hadoop
后端·python·mysql
2***c43517 小时前
Redis——使用 python 操作 redis 之从 hmse 迁移到 hset
数据库·redis·python