Easy
%4
来区分步骤python3
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
if len(matrix) == 0:
return []
r = []
m = len(matrix)
n = len(matrix[0])
count = 0
i = 0
j = 0
for k in range(m * n):
#print((i,j))
r.append(matrix[i][j])
if count % 4 == 0:
if j < (n - 1 - int(count / 4)):
j +=1
else:
i+=1
count += 1
elif count % 4 == 1:
if i < (m - 1 - int(count / 4)):
i +=1
else:
j-=1
count +=1
elif count % 4 == 2:
if j > int(count / 4):
j-=1
else:
i-=1
count +=1
else:
if i> int(count/4) + 1:
i-=1
else:
j+=1
count +=1
return r