Skip to content

Commit 221d029

Browse files
committed
Time: 767 ms (5.06%), Space: 72.6 MB (5.06%) - LeetHub
1 parent e67b22f commit 221d029

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)