# Question

Formatted question description: https://leetcode.ca/all/49.html

49	Group Anagrams

Given an array of strings, group anagrams together.

For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
Return:
[
["ate", "eat","tea"],
["nat","tan"],
["bat"]
]

Note:
For the return value, each inner list's elements must follow the lexicographic order.
All inputs will be in lower-case.

@tag-hashtable


# Algorithm

### With sort

How to judge whether the two are misplaced words? It can be found that if the character order of the misplaced words is rearranged, the same result will be obtained. Therefore, reordering is a way to judge whether the two are misplaced words.

Use the same string as the key, save all misplaced words in the string array, and establish a mapping between the key and the number of different sets of misplaced words. The reason why there is no dislocation between the key and its membership is established here The mapping between word sets uses a small trick to avoid copying the set in the HashMap to the result res at the end.

When it is detected that the current word is not in the HashMap, it is known that the word will belong to a new set of misplaced words, so it is mapped to the number of the current set of misplaced words, and then an empty set is added to res, so that You can directly find the position of the new misplaced word set through its mapping value, so as to store the new word in the result.

### No sort

Use an int array with a size of 26 to count the number of occurrences of characters in each word, and then convert the int array into a unique string, and map it with the string array, so that there is no need to sort the strings.

Java