[Java][LeetCode][Hash] Group Anagrams

SP Hou
Jul 6, 2022

--

題目要求將同樣字母組成的字串分類成一個群組,所以將每個字串轉成char[]並且sort,sort後再重組成字串當map的key,把原字串加進去value(value的type是List<String>),最後把values全部倒去List<List<String>>並回出去。

This problem request to classify by a string of the same letter. I split the string into a character array and sorted it. Restructure the sorted char array to a string and it will be a key to the map. Added original string into the value of the map. At last, get the values of the map to List<List<String>> and return it.

--

--