问题描述(原题链接)
代码:
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
int index=0;
HashMap<String,Integer> map = new HashMap<String,Integer>();
List<List<String>> list = new ArrayList<List<String>>();
int len = strs.length;
for(int i=0;i<len;i++){
char[] temp = strs[i].toCharArray();
Arrays.sort(temp);
if(map.containsKey(new String(temp))){
int j = map.get(new String(temp));
list.get(j).add(strs[i]);
}else{
map.put(new String(temp),list.size());
List<String> temp2 = new ArrayList<String>();
temp2.add(strs[i]);
list.add(temp2);
}
}
return list;
}
}