forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path73-Set-Matrix-Zeros.kt
More file actions
36 lines (31 loc) · 827 Bytes
/
73-Set-Matrix-Zeros.kt
File metadata and controls
36 lines (31 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
fun setZeroes(matrix: Array<IntArray>): Unit {
var m = matrix.size
var n = matrix[0].size
var isCol = false
for (i in 0..m-1) {
if (matrix[i][0] == 0)
isCol = true
for (j in 1..n-1) {
if (matrix[i][j] == 0) {
matrix[i][0] = 0
matrix[0][j] = 0
}
}
}
for (i in 1..m-1) {
for (j in 1..n-1) {
if (matrix[0][j] == 0 || matrix[i][0] == 0)
matrix[i][j] = 0
}
}
if (matrix[0][0] == 0) {
for (j in 0..n-1)
matrix[0][j] = 0
}
if (isCol) {
for (i in 0..m-1)
matrix[i][0] = 0
}
}
}