leetcode-----49. 字母异位词分组

代码

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> map;
        for (auto &str: strs) {
            string key = str;
            sort(key.begin(), key.end());
            map[key].push_back(move(str));
        }
        vector<vector<string>> ans;

        for (auto i = map.begin(); i != map.end(); ++i) {
            ans.push_back(move(i->second));
        }
        return ans;
    }
};
posted @ 2020-07-06 21:30  景云ⁿ  阅读(60)  评论(0编辑  收藏  举报