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 2cd028d commit 17b3360Copy full SHA for 17b3360
set-matrix-zeroes/gmlwls96.kt
@@ -0,0 +1,27 @@
1
+class Solution {
2
+ // 시간 : O(mn) 공간 : O(m+n)
3
+ // 변경해야되는 position 찾아 yList, xList에 각각 y,x값을 담되 set을 이용하여 중복을 제거한다.
4
+ // yList, xList를 조회하며 matrix를 변경해준다.
5
+ fun setZeroes(matrix: Array<IntArray>): Unit {
6
+ val yList = mutableSetOf<Int>()
7
+ val xList = mutableSetOf<Int>()
8
+ for (y in 0 until matrix.size) {
9
+ for (x in 0 until matrix[y].size) {
10
+ if (matrix[y][x] == 0) {
11
+ yList.add(y)
12
+ xList.add(x)
13
+ }
14
15
16
+ yList.forEach { y ->
17
18
+ matrix[y][x] = 0
19
20
21
+ xList.forEach { x ->
22
23
24
25
26
27
+}
0 commit comments