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;
    }
};
上一篇:直接插入排序


下一篇:小程序:授权、登录、session_key、unionId