-
Notifications
You must be signed in to change notification settings - Fork 3
/
solution.go
48 lines (44 loc) · 898 Bytes
/
solution.go
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
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"math"
)
func setZeroes(matrix [][]int) {
for i := range matrix {
for j := range matrix[i] {
// find the zero value
if matrix[i][j] == 0 {
// set all non zero values in the zero value row to math.MinInt64
for k := range matrix {
if matrix[k][j] != 0 {
matrix[k][j] = math.MinInt64
}
}
// set all non zero values in the zero value col to math.MinInt64
for k := range matrix[i] {
if matrix[i][k] != 0 {
matrix[i][k] = math.MinInt64
}
}
}
}
}
// find all values equals to math.MinInt64 and set them to zero
for i := range matrix {
for j := range matrix[i] {
if matrix[i][j] == math.MinInt64 {
matrix[i][j] = 0
}
}
}
}
func main() {
matrix := [][]int{
{0, 1, 2, 0},
{3, 4, 5, 2},
{1, 3, 1, 5},
}
setZeroes(matrix)
fmt.Println(math.MinInt64)
fmt.Printf("%#v", matrix)
}