class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
left = 0
right = len(matrix[0]) - 1
down = len(matrix) - 1
up = 0
while left <= right and up <= down:
if left <= right:
for i in range(left, right + 1, 1):
res.append(matrix[up][i])
up += 1
if down >= up:
for i in range(up, down + 1, 1):
res.append(matrix[i][right])
right -= 1
if left <= right:
for i in range(right, left - 1, -1):
res.append(matrix[down][i])
down -= 1
if down >= up:
for i in range(down, up - 1, -1):
res.append(matrix[i][left])
left += 1
return res
标签:right,matrix,螺旋,Python,res,List,up,数组,left
From: https://www.cnblogs.com/DCFV/p/18406620