# 螺旋矩阵

<p>给你一个 <code>m</code> 行 <code>n</code> 列的矩阵 <code>matrix</code> ，请按照 <strong>顺时针螺旋顺序</strong> ，返回矩阵中的所有元素。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/0d476dcc094b85563f4f43c393ef1425.jpeg" style="width: 242px; height: 242px;" /><pre><strong>输入：</strong>matrix = [[1,2,3],[4,5,6],[7,8,9]]<strong><br />输出：</strong>[1,2,3,6,9,8,7,4,5]</pre><p><strong>示例 2：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/1c83ff2d8f7cc194b08715bacdedff99.jpeg" style="width: 322px; height: 242px;" /><pre><strong>输入：</strong>matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]<strong><br />输出：</strong>[1,2,3,4,8,12,11,10,9,5,6,7]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>m == matrix.length</code></li>	<li><code>n == matrix[i].length</code></li>	<li><code>1 <= m, n <= 10</code></li>	<li><code>-100 <= matrix[i][j] <= 100</code></li></ul>

## 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

```