问题描写叙述:
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.
比如:输入为:{abc,bca,123,321,567} 输出为:{abc,bca,123,321} 解决方式:class Solution {public: vectoranagrams(vector &strs) { int len = strs.size(); map map1; vector result; for(int i = 0; i< len;i++) { string temp = strs[i]; sort(temp.begin(),temp.end()); if(map1.count(temp)){ if(map1[temp]>=0) { result.push_back(strs[map1[temp]]); map1[temp] = -1; result.push_back(strs[i]); }else { result.push_back(strs[i]); } }else{ map1[temp] = i; } } return result; }};