problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::group_anagrams::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< vector< string > > groupAnagrams (vector< string > &strs)
 

详细描述

在文件 leetcode.h2555 行定义.

成员函数说明

◆ groupAnagrams()

vector< vector< string > > leetcode::group_anagrams::Solution::groupAnagrams ( vector< string > &  strs)
static

在文件 leetcode.cpp6872 行定义.

6872 {
6873 vector<string> strs_sorted = strs;
6874 unordered_map<string, vector<string>> um;
6875 for(auto &str: strs_sorted) {
6876 sort(str.begin(), str.end());
6877 if(!um.contains(str)) {
6878 um[str] = vector<string>();
6879 }
6880 }
6881 for(int i = 0; i < strs.size(); i++) {
6882 um[strs_sorted[i]].emplace_back(strs[i]);
6883 }
6884 vector<vector<string>> ans;
6885 ans.reserve(um.size());
6886 for(auto &[k, v]: um) {
6887 ans.emplace_back(v);
6888 }
6889 return ans;
6890 }

该类的文档由以下文件生成: