Created
May 22, 2017 22:06
-
-
Save BiruLyu/9f50c07cec4d8ffd11b061e0d6588ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public String countChar(String str){ | |
int[] vector = new int[26]; | |
for(char c : str.toCharArray()){ | |
vector[c - 'a']++; | |
} | |
return Arrays.toString(vector); | |
} | |
public List<List<String>> groupAnagrams(String[] strs) { | |
HashMap<String,List<String>> map = new HashMap<String, List<String>>(); | |
for(String str : strs){ | |
String temp = countChar(str); | |
if(!map.containsKey(temp)){ | |
map.put(temp, new ArrayList<String>()); | |
} | |
map.get(temp).add(str); | |
} | |
return new ArrayList<List<String>>(map.values()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow