mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Merge pull request #5 from janeyziqinglin/janeyziqinglin-patch-5
Update 0054.螺旋矩阵 python版本
This commit is contained in:
@ -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)
|
||||
```
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user