diff --git a/problems/0054.螺旋矩阵.md b/problems/0054.螺旋矩阵.md index ccf6f471..27899d51 100644 --- a/problems/0054.螺旋矩阵.md +++ b/problems/0054.螺旋矩阵.md @@ -171,6 +171,30 @@ class Solution: return res ``` - +```python3 +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + r=len(matrix) + if r == 0 or len(matrix[0])==0: + return [] + c=len(matrix[0]) + res=matrix[0] + + if r>1: + for i in range (1,r): + res.append(matrix[i][c-1]) + for j in range(c-2, -1, -1): + res.append(matrix[r-1][j]) + if c>1: + for i in range(r-2, 0, -1): + res.append(matrix[i][0]) + + M=[] + for k in range(1, r-1): + e=matrix[k][1:-1] + M.append(e) + + return res+self.spiralOrder(M) +``` -----------------------