30 Days of Code [Day 2]
QUESTION : 49. Group Anagrams
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define printv(v) for(auto &x : v){cout<<x<<" ";}cout<<endl;
#define fv(V) for( auto &x : V )
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> m;
fv(strs){
string t = x;
sort(all(t));
m[t].pb(x);
}
vector<vector<string>> res;
fv(m) res.pb(x.second);
return res;
}
};