We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e67b22f commit 221d029Copy full SHA for 221d029
0049-group-anagrams/0049-group-anagrams.kt
@@ -0,0 +1,12 @@
1
+class Solution {
2
+ fun groupAnagrams(strs: Array<String>): List<List<String>> {
3
+ val map = mutableMapOf<String, MutableList<String>>()
4
+ strs.forEachIndexed{ index, word ->
5
+ val sortedWord = word.toCharArray().sorted().joinToString("")
6
+ if(!map.containsKey(sortedWord)) map[sortedWord] = mutableListOf<String>()
7
+ map[sortedWord]?.add(word)
8
+ }
9
+
10
+ return map.values.toList()
11
12
+}
0 commit comments