Skip to content

Latest commit

 

History

History
 
 

groupAnagrams

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

字母异位词分组

LeetCode地址

代码

class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] cs = str.toCharArray();
            Arrays.sort(cs);
            String anagram = String.valueOf(cs);
            if (!map.containsKey(anagram))
                map.put(anagram, new ArrayList<String>());
            map.get(anagram).add(str);
        }
        return new ArrayList(map.values());
    }
}