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.
1 parent 80d8807 commit 780c0c5Copy full SHA for 780c0c5
spiral-matrix/daiyongg-kim.py
@@ -0,0 +1,27 @@
1
+class Solution:
2
+ def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
3
+ res = []
4
+ left, right = 0, len(matrix[0])
5
+ top, bottom = 0, len(matrix)
6
+
7
+ while left < right and top < bottom:
8
+ for i in range(left, right):
9
+ res.append(matrix[top][i])
10
+ top += 1
11
12
+ for i in range(top, bottom):
13
+ res.append(matrix[i][right - 1])
14
+ right -= 1
15
16
+ if not (left < right and top < bottom):
17
+ break
18
19
+ for i in range(right -1, left -1, -1):
20
+ res.append(matrix[bottom - 1][i])
21
+ bottom -= 1
22
23
+ for i in range(bottom - 1, top - 1, -1):
24
+ res.append(matrix[i][left])
25
+ left += 1
26
27
+ return res
0 commit comments