标签:cond example you red pre desc 题目 turn 字符
Given an array of strings, group anagrams together.
Example:
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
,
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
sort(s.begin(),s.end());
1 class Solution { 2 public: 3 vector<vector<string>> groupAnagrams(vector<string>& strs) { 4 unordered_map<string,vector<string>> map; //key:sorted string, value: vector of strings with the same key 5 for(auto s: strs){ 6 string tmp = s; 7 sort(tmp.begin(),tmp.end()); 8 map[tmp].push_back(s); 9 } 10 11 vector<vector<string>> result; 12 for(auto it: map){ 13 result.push_back(it.second); 14 } 15 16 return result; 17 } 18 };
标签:cond example you red pre desc 题目 turn 字符
原文地址:https://www.cnblogs.com/ruisha/p/9603865.html