The idea is to peel the the matrix layer by layer.

```
class Solution:
# @param matrix, a list of lists of integers
# @return a list of integers
# 9:27
def spiralOrder(self, matrix):
result = []
while matrix and matrix[0]:
if matrix[0]:
result += matrix.pop(0)
if matrix and matrix[0]:
for row in matrix:
result.append(row.pop())
if matrix and matrix[-1]:
result += matrix.pop()[::-1]
if matrix and matrix[0]:
for row in matrix[::-1]:
result.append(row.pop(0))
return result
```