自学内容网 自学内容网

Leetcode49. 字母异位词分组 -hot100

题目:


代码(首刷看解析 2024年3月2日):

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> groups;
        for (const string& str : strs) {
            string key = str;
            sort(key.begin(), key.end());
            groups[key].push_back(str);
        }
        vector<vector<string>> result;
        for (const unordered_map<string, vector<string>>::value_type& it : groups)
            result.push_back(it.second);
        return result;
    }
};


原文地址:https://blog.csdn.net/qq_52313711/article/details/136412130

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!