Description
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
解法
这题就按照四个方向来进行数组的遍历,注意方向的转换与边界的处理,同时注意处理一行,一列为空的特殊情况。
具体代码如下:
1 | class Solution { |
Thinking outside the box
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
这题就按照四个方向来进行数组的遍历,注意方向的转换与边界的处理,同时注意处理一行,一列为空的特殊情况。
具体代码如下:
1 | class Solution { |