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 1381be3 commit 0e7cb61Copy full SHA for 0e7cb61
group-anagrams/gmlwls96.kt
@@ -0,0 +1,20 @@
1
+class Solution {
2
+
3
+ /**
4
+ * 시간 : O(n*wlogw), 공간 : O(n*w)
5
+ * 풀이
6
+ * 1. strs를 한개씩 조회하며 strs[i]를 정렬한 값을 key값, value값은 list(strs[i])형태로 추가한다.
7
+ * 2. return 형태에 맞게 map의 value만 뽑아낸다.
8
+ * */
9
+ fun groupAnagrams(strs: Array<String>): List<List<String>> {
10
+ val map = mutableMapOf<String, MutableList<String>>()
11
+ strs.forEach {
12
+ val key = it.toCharArray()
13
+ .sortedArray()
14
+ .joinToString("")
15
+ map[key] = map.getOrElse(key) { mutableListOf() }
16
+ .apply { add(it) }
17
+ }
18
+ return map.map { it.value }
19
20
+}
0 commit comments