Leetcode每日一题-2021-7-18<变位词组>(STL)
作者:互联网
链接:https://leetcode-cn.com/problems/group-anagrams-lcci/
思路:
- 对string排序后作为键值,map嵌套vector
数组
万物皆可map,万物皆可sort
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& s) {
map<string,vector<string>>m;
vector<vector<string>>v;
for(int i=0;i<s.size();i++){
string str=s[i];
sort(str.begin(),str.end());
m[str].emplace_back(s[i]);
}
for(auto i:m){
v.emplace_back(i.second);
}
return v;
}
};
标签:map,cn,STL,18,int,vector,键值,2021,万物 来源: https://www.cnblogs.com/abestxun/p/15025987.html