CODE >>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>> ans;
unordered_map<string, vector<string>> dict;
int i = 0;
for (auto& str : strs)
{
string tempstring = str;
std::sort(tempstring.begin(), tempstring.end());
dict[tempstring].emplace_back(str);
}
for (auto& vec : dict)
{
ans.emplace_back(vec.second);
}
return ans;
}
};
|
'C' 카테고리의 다른 글
c++ leet code 20. Valid Parentheses stack solution (0) | 2021.07.07 |
---|---|
c++ leetcode O(N) solution Longest Substring Without repetition (0) | 2021.07.07 |
c++ leetcode 415 AddStrings solution (0) | 2021.07.06 |
c++ leetcode 680번 valid palindrome II (0) | 2021.07.06 |
c++ leetcode 125 valid palindrome solution (0) | 2021.07.06 |