LeetCode -- Anagrams
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
Anman is the English word used in the game of misplacement and word formation, this word comes from the Greek roots ana-And grahpein, which have the meaning of "reverse" or "re. The inverted word formation is a kind of word games (more accurately, it is a kind of "word games"). It re-arranges the letters in a word or short sentence, each occurrence of all letters in the original text is used to create other words or short sentences. Http://zh.wikipedia.org/wiki/%E6%98%93%E4%BD%8D%E6%9E%84%E8%AF%8D%E6%B8%B8%E6%88%8F
public List
anagrams(String[] strs) {List
list = new ArrayList
();Map
> map = new HashMap
>();for(String str : strs){char[] ch = str.toCharArray();Arrays.sort(ch);String s = new String(ch);if(map.containsKey(s))map.get(s).add(str);else{List
li = new ArrayList
();li.add(str);map.put(s,li);}}for(List
ls : map.values()){if(ls.size() > 1)list.addAll(ls);}return list;}