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.
2 parents dd6ec45 + b00d70a commit 6456d30Copy full SHA for 6456d30
swift/0073-set-matrix-zeroes.swift
@@ -0,0 +1,39 @@
1
+class Solution {
2
+ func setZeroes(_ matrix: inout [[Int]]) {
3
+ let rows = matrix.count, cols = matrix[0].count
4
+ var rowZero = false
5
+
6
+ for r in 0..<rows {
7
+ for c in 0..<cols {
8
+ if matrix[r][c] == 0 {
9
+ matrix[0][c] = 0
10
+ if r > 0 {
11
+ matrix[r][0] = 0
12
+ } else {
13
+ rowZero = true
14
+ }
15
16
17
18
19
+ for r in 1..<rows {
20
+ for c in 1..<cols {
21
+ if matrix[0][c] == 0 || matrix[r][0] == 0 {
22
+ matrix[r][c] = 0
23
24
25
26
27
+ if matrix[0][0] == 0 {
28
29
30
31
32
33
+ if rowZero {
34
35
36
37
38
39
+}
0 commit comments