Skip to content

Commit cee42e2

Browse files
committed
create go version of daily
1 parent 28b187c commit cee42e2

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

my-submissions/m498 golang.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
func findDiagonalOrder(mat [][]int) []int {
2+
var output []int
3+
dirr := 1
4+
i, j := 0, 0
5+
6+
for i < len(mat) && j < len(mat[0]) {
7+
output = append(output, mat[i][j])
8+
9+
a, b := i - dirr, j + dirr
10+
11+
if (0 <= a && a < len(mat)) && (0 <= b && b < len(mat[0])) {
12+
i = a
13+
j = b
14+
continue
15+
}
16+
17+
if dirr == 1 {
18+
if j + 1 < len(mat[0]) {
19+
j += 1
20+
} else {
21+
i += 1
22+
}
23+
dirr *= -1
24+
continue
25+
}
26+
27+
if i + 1 < len(mat) {
28+
i += 1
29+
} else {
30+
j += 1
31+
}
32+
dirr *= -1
33+
}
34+
35+
return output
36+
}

my-submissions/m498.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:
1616
if dirr == 1 :
1717
if j + 1 < len(mat[0]) :
1818
j += 1
19-
dirr *= -1
2019
else :
2120
i += 1
22-
dirr *= -1
21+
dirr *= -1
2322
continue
2423

2524
# Moving down to the left
2625
if i + 1 < len(mat) :
2726
i += 1
28-
dirr *= -1
2927
else :
3028
j += 1
31-
dirr *= -1
29+
dirr *= -1
3230

3331
return output

0 commit comments

Comments
 (0)