标签:put str group lin info NPU code push map
Given an array of strings, group anagrams together.
Example:
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
,
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
AC code:
class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { unordered_map<string, vector<string>> mp; vector<vector<string>> res; for (auto str : strs) { string tage = str; sort(tage.begin(), tage.end()); mp[tage].push_back(str); } for (auto m : mp) { sort(m.second.begin(), m.second.end()); res.push_back(m.second); } return res; } };
标签:put str group lin info NPU code push map
原文地址:https://www.cnblogs.com/ruruozhenhao/p/9807315.html