Skip to content

Commit a5b00e6

Browse files
authored
Create 2610-convert-an-array-into-a-2d-array-with-conditions.kt
1 parent 6289169 commit a5b00e6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun findMatrix(nums: IntArray): List<List<Int>> {
3+
val count = HashMap<Int, Int>()
4+
val res = mutableListOf<MutableList<Int>>()
5+
6+
for (n in nums) {
7+
var row = count[n] ?: 0
8+
if (res.size == row)
9+
res.add(mutableListOf<Int>())
10+
res[row].add(n)
11+
count[n] = (count[n] ?: 0) + 1
12+
}
13+
14+
return res
15+
}
16+
}

0 commit comments

Comments
 (0)