171.Anagrams
1.Description(Medium)
Given an array of strings, return all groups of strings that are anagrams.
Notice
All inputs will be in lower-case
Example
Given["lint", "intl", "inlt", "code"]
, return["lint", "inlt", "intl"]
.
Given["ab", "ba", "cd", "dc", "e"]
, return["ab", "ba", "cd", "dc"]
.
What is Anagram?
Two strings are anagram if they can be the same after change the order of characters.
2.Code
用一个HashMap<String,List<String>>来记录,取出每个string排序然后把与原顺序的string记录进hashmap的list中,最后判断ma。p.values()里面的每个list的size如果>1,就说明有他的anagrams,直接addAll进去就行了。
Last updated