【力扣专题栏】字母异词分组,如何利用强大的容器(unordered_map)解决该问题?

题解目录

1、题目描述+解释

2、算法原理解析

3、代码编写

cpp 复制代码
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        //创建哈希表
        unordered_map<string,vector<string>> hash;
        //遍历
        for(auto& s:strs)
        {
            string tmp=s;
            //排序
            sort(tmp.begin(),tmp.end());
            //插入到key为tmp对应的vector中去
            hash[tmp].push_back(s);
        }
        vector<vector<string>> ret;
        for(auto& h:hash)
        {
            ret.push_back(h.second);
        }
        return ret;
    }
};
相关推荐
多米Domi01113 小时前
0x3f第33天复习 (16;45-18:00)
数据结构·python·算法·leetcode·链表
Lips61114 小时前
2026.1.16力扣刷题
数据结构·算法·leetcode
今天_也很困15 小时前
LeetCode 热题100-15.三数之和
数据结构·算法·leetcode
千金裘换酒16 小时前
LeetCode 数组经典题刷题
算法·leetcode·职场和发展
alphaTao17 小时前
LeetCode 每日一题 2026/1/12-2026/1/18
python·算法·leetcode
sin_hielo17 小时前
leetcode 2943
数据结构·算法·leetcode
程序员-King.19 小时前
day134—快慢指针—环形链表(LeetCode-141)
算法·leetcode·链表·快慢指针
Swift社区19 小时前
LeetCode 376 摆动序列
算法·leetcode·职场和发展
Morwit20 小时前
*【力扣hot100】 448. 找到所有数组中消失的数字
数据结构·算法·leetcode
0和1的舞者21 小时前
力扣hot100-链表专题-刷题笔记(二)
笔记·算法·leetcode·链表·职场和发展