Leetcode 49. 字母异位词分组(DAY 87) ---- Leetcode Hot 100
发布日期:2021-06-30 22:29:27 浏览次数:2 分类:技术文章

本文共 626 字,大约阅读时间需要 2 分钟。

原题题目

在这里插入图片描述


代码实现(首刷自解 太烧了这能AC)

class Solution {
public: vector
> groupAnagrams(vector
& strs) {
multimap
m; unordered_set
s; int count = 0; for(const auto& str:strs) {
auto temp(str); sort(temp.begin(),temp.end()); s.insert(temp); m.insert(make_pair(temp,str)); } vector
> ret(s.size()); for(const auto& str:s) { auto left = m.lower_bound(str); auto right = m.upper_bound(str); while(left != right) ret[count].push_back((left++)->second); ++count; } return ret; }};

转载地址:https://love6.blog.csdn.net/article/details/115749885 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Leetcode 215. 数组中的第K个最大元素(DAY 87) ---- Leetcode Hot 100
下一篇:Leetcode 287. 寻找重复数(DAY 86) ---- Leetcode Hot 100

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月22日 10时55分49秒