Clean Java Code


  • 0
    A
    public List<List<String>> groupAnagrams(String[] strs) {
    	Map<String, List<String>> map = new HashMap<String, List<String>>();
    	for (String s : strs) {
    		char[] arr = s.toCharArray();
    		Arrays.sort(arr);
    		String key = new String(arr);
    		if (map.get(key) == null)
    			map.put(key, new LinkedList<String>());
    		map.get(key).add(s);
    	}
    	return new LinkedList<List<String>>(map.values());
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.