[Programmers] 54. Spiral Matrix
Python
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
answer = []
while matrix:
answer += matrix.pop(0)
if matrix and matrix[0]:
for i in matrix:
answer.append(i.pop())
if matrix:
answer += matrix.pop()[::-1]
if matrix and matrix[0]:
for i in matrix[::-1]:
answer.append(i.pop(0))
return answer
댓글남기기