标签:
//hashmap implement with STL class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { // sort(strs.begin(),strs.end()); //sort all the element map<string,vector<string>>hashmap; for(vector<string>::iterator it=strs.begin();it!=strs.end();it++) { string str=*it; sort(str.begin(),str.end()); hashmap[str].push_back(*it); //hashmap; } vector<vector<string>>re; for(map<string,vector<string>>::iterator it=hashmap.begin();it!=hashmap.end();it++) //each group with the same key re.push_back(it->second); return re; } };
标签:
原文地址:http://www.cnblogs.com/zeroArn/p/5875482.html