54. Spiral Matrix
Difficulty: Medium
Given a matrix of _m_ x _n_ elements (_m_ rows, _n_ columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
1 | [ |
You should return [1,2,3,6,9,8,7,4,5].
Solution
定义四个方向,遇到不能前进就换方向,直到list的大小和数组元素大小相同。
1 | class Solution { |