Skip to content

Commit e6bd1f9

Browse files
Merge pull request #1635 from CodingTestStudy2/최원준
[최원준] Day05
2 parents 6b323d9 + bb1c229 commit e6bd1f9

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
-
6+
7+
2. 시간복잡도 :
8+
O(n * m)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
15+
class Solution:
16+
def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:
17+
ans = []
18+
n = len(mat)
19+
m = len(mat[0])
20+
21+
def get_next(x: int, y: int, going_up: bool):
22+
if going_up:
23+
if x == 0:
24+
if y == m - 1:
25+
return [x + 1, y]
26+
else:
27+
return [x, y + 1]
28+
elif y == m - 1:
29+
return [x + 1, y]
30+
else:
31+
return [x - 1, y + 1]
32+
33+
else:
34+
if y == 0:
35+
if x == n - 1:
36+
return [x, y + 1]
37+
else:
38+
return [x + 1, y]
39+
elif x == n - 1:
40+
return [x, y + 1]
41+
else:
42+
return [x + 1, y - 1]
43+
44+
x = y = 0
45+
going_up = True
46+
47+
for _ in range(n * m):
48+
ans.append(mat[x][y])
49+
nx, ny = get_next(x, y, going_up)
50+
51+
if nx != x - 1 and nx != x + 1:
52+
going_up = not going_up
53+
elif ny != y - 1 and ny != y + 1:
54+
going_up = not going_up
55+
56+
x, y = nx, ny
57+
58+
return ans

0 commit comments

Comments
 (0)