0054. 螺旋矩阵 #55
utterances-bot
started this conversation in
Comments
Replies: 2 comments
-
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
while matrix:
res += matrix.pop(0)
if not matrix:
break
matrix = self.turnMatrix(matrix)
return res
def turnMatrix(self, matrix: List[List[int]]) -> List[int]:
rows = len(matrix)
cols = len(matrix[0])
newmat = []
for i in range(cols):
newrow = []
for j in range(rows):
newrow.append(matrix[j][i])
newmat.append(newrow)
newmat.reverse()
return newmat |
Beta Was this translation helpful? Give feedback.
0 replies
-
class Solution:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0054. 螺旋矩阵 | 算法通关手册
https://algo.itcharge.cn/Solutions/0001-0099/spiral-matrix/
Beta Was this translation helpful? Give feedback.
All reactions