东莞网站建设有什么网络公司,招商网站怎么做,wordpress网址访问慢,帮别人做网站收多少钱合适推荐博客#xff1a;
for(auto i : v)遍历容器元素_for auto 遍历-CSDN博客 字母异位词都有一个特点#xff1a;也就是对这个词排序之后结果会相同。所以将排序之后的string作为key#xff0c;将排序之后能变成key的单词组vectorstring作为value。 class Solution …
推荐博客
for(auto i : v)遍历容器元素_for auto 遍历-CSDN博客 字母异位词都有一个特点也就是对这个词排序之后结果会相同。所以将排序之后的string作为key将排序之后能变成key的单词组vectorstring作为value。 class Solution {
public:vectorvectorstring groupAnagrams(vectorstring strs) {unordered_mapstring,vectorstring hmap;int lenstrs.size();for(int i0;ilen;i){string tempstrs[i];sort(temp.begin(),temp.end());hmap[temp].emplace_back(strs[i]);}vectorvectorstring res;int len_hmaphmap.size();for(auto i:hmap){res.emplace_back(i.second);}return res;}
}; 1.sort字符串写法
sort(temp.begin(),temp.end());
2.在 vector 容器尾部添加一个元素
hmap[temp].emplace_back(strs[i]);
3.遍历哈希表value for(auto i:hmap){res.emplace_back(i.second);}