# 螺旋矩阵

给你一个 mn 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。

 

示例 1:

输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:
[1,2,3,6,9,8,7,4,5]

示例 2:

输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
输出:
[1,2,3,4,8,12,11,10,9,5,6,7]

 

提示:

## template ```python class Solution(object): def spiralOrder(self, matrix): """ :type matrix: List[List[int]] :rtype: List[int] """ if matrix is None or len(matrix) == 0: return matrix m, n = len(matrix), len(matrix[0]) return self.get_spiralOrder(matrix, 0, m - 1, 0, n - 1) def get_spiralOrder(self, matrix, r_start, r_end, c_start, c_end): if r_start > r_end or c_start > c_end: return [] elif r_start == r_end: return matrix[r_start][c_start:c_end + 1] elif c_start == c_end: return [matrix[j][c_end] for j in range(r_start, r_end + 1)] curr = matrix[r_start][c_start:c_end + 1] + [matrix[j][c_end] for j in range(r_start + 1, r_end)] +\ matrix[r_end][c_start:c_end + 1][::-1] +\ [matrix[j][c_start] for j in reversed(range(r_start + 1, r_end))] res = curr + self.get_spiralOrder(matrix, r_start + 1, r_end - 1, c_start + 1, c_end - 1) return res if __name__ == '__main__': s = Solution() print (s.spiralOrder([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])) ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```