class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>> result;
if (strs.empty()) return result;
sort(strs.begin(), strs.end());
map<string, vector<string>> mv;
for(int i = 0; i < strs.size(); i++) {
string str = strs[i];
sort(str.begin(), str.end());
mv[str].push_back(strs[i]);
}
for(map<string, vector<string> >::iterator iter = mv.begin(); iter != mv.end(); iter++) {
result.push_back(iter->second);
}
return result;
}
};