Skip to content

Commit b61afe9

Browse files
Update 0054.螺旋矩阵.md
for loop version of python3 solution
1 parent 87abfa1 commit b61afe9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

problems/0054.螺旋矩阵.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ class Solution:
171171

172172
return res
173173
```
174-
174+
```python3
175+
class Solution:
176+
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
177+
r=len(matrix)
178+
if r == 0 or len(matrix[0])==0:
179+
return []
180+
c=len(matrix[0])
181+
res=matrix[0]
182+
183+
if r>1:
184+
for i in range (1,r):
185+
res.append(matrix[i][c-1])
186+
for j in range(c-2, -1, -1):
187+
res.append(matrix[r-1][j])
188+
if c>1:
189+
for i in range(r-2, 0, -1):
190+
res.append(matrix[i][0])
191+
192+
M=[]
193+
for k in range(1, r-1):
194+
e=matrix[k][1:-1]
195+
M.append(e)
196+
197+
return res+self.spiralOrder(M)
198+
```
175199
-----------------------
176200
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
 (0)