Created
October 14, 2016 00:04
-
-
Save Roger7410/0629b2b5ef39879239d60d0675608ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 List<List<String>> groupAnagrams(String[] strs) { | |
| if(strs.length < 1 || strs == null) return new ArrayList<List<String>>(); | |
| Map<String,List<String>> map = new HashMap<>(); | |
| for(String s: strs){ | |
| char[] chars = s.toCharArray(); | |
| Arrays.sort(chars); | |
| String key = String.valueOf(chars); | |
| if(!map.containsKey(key)) map.put(key, new ArrayList<String>()); | |
| map.get(key).add(s); | |
| } | |
| 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