We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: m = len(matrix) if m == 0: return [] if m == 1: return matrix[0] # 矩阵只有一行 if m == 2: return matrix[0] + matrix[1][::-1] # 矩阵只有两行 if len(matrix[0]) == 0: return [] # 矩阵一行里没有值 if len(matrix[0]) == 1: # 矩阵一行里只有一个值 result = [] for m in matrix: result += m return result up = matrix.pop(0) # 第一个 bottom = matrix.pop() # pop最后一个 left, right = [], [] for i in range(len(matrix)): left.append(matrix[i].pop(0)) right.append(matrix[i].pop()) # [::-1] 数组逆序 return up + right + bottom[::-1] + left[::-1] + self.spiralOrder(matrix)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1 - 打印矩阵
剑指 Offer 29. 顺时针打印矩阵
同 54. 螺旋矩阵
The text was updated successfully, but these errors were encountered: