Description
Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word formed by rearranging the letters of a different word, using all the original letters exactly once.
Examples
strs = ["eat","tea","tan","ate","nat","bat"][["bat"],["nat","tan"],["ate","eat","tea"]]Sorting each word alphabetically gives: eat->aet, tea->aet, tan->ant, ate->aet, nat->ant, bat->abt. Words with the same sorted form are anagrams: 'aet' group contains [eat,tea,ate], 'ant' group contains [tan,nat], 'abt' group contains [bat].
strs = [""][[""]]An empty string has no characters to sort, so its sorted key is also empty. Since there is only one empty string, it forms a single-element group by itself.
strs = ["a"][["a"]]The single character 'a' sorted is still 'a'. With no other strings sharing this key, 'a' forms its own group containing just itself.
Constraints
- •
1 ≤ strs.length ≤ 10⁴ - •
0 ≤ strs[i].length ≤ 100 - •
strs[i] consists of lowercase English letters.