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 9100c95 commit b71a31dCopy full SHA for b71a31d
group-anagrams/hyunjung-choi.kt
@@ -0,0 +1,18 @@
1
+/**
2
+ * N: 단어 개수, M: 평균 단어 길이
3
+ * 시간 복잡도: O(N × M log M)
4
+ * 공간 복잡도: O(N × M)
5
+ */
6
+
7
+class Solution {
8
+ fun groupAnagrams(strs: Array<String>): List<List<String>> {
9
+ val groupMap = mutableMapOf<String, MutableList<String>>()
10
11
+ for (str in strs) {
12
+ val sortedKey = str.toCharArray().sorted().joinToString("")
13
+ groupMap.getOrPut(sortedKey) { mutableListOf()}.add(str)
14
+ }
15
16
+ return groupMap.values.toList()
17
18
+}
0 commit comments