{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "283dc07c5cdf4aedb15f3ecfffcaa9eb",
  "keywords": "数组,矩阵,模拟",
  "title": "螺旋矩阵",
  "desc": [
    {
      "content": "\n<p>给你一个 <code>m</code> 行 <code>n</code> 列的矩阵 <code>matrix</code> ，请按照 <strong>顺时针螺旋顺序</strong> ，返回矩阵中的所有元素。</p><p> </p><p><strong>示例 1：</strong></p><img alt=\"\" src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0054.Spiral%20Matrix/images/spiral1.jpg\" 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://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0054.Spiral%20Matrix/images/spiral.jpg\" 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>\t<li><code>m == matrix.length</code></li>\t<li><code>n == matrix[i].length</code></li>\t<li><code>1 <= m, n <= 10</code></li>\t<li><code>-100 <= matrix[i][j] <= 100</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef spiralOrder(self, matrix):\n\t\t\"\"\"\n\t\t:type matrix: List[List[int]]\n\t\t:rtype: List[int]\n\t\t\"\"\"\n\t\tif matrix is None or len(matrix) == 0:\n\t\t\treturn matrix\n\t\tm, n = len(matrix), len(matrix[0])\n\t\treturn self.get_spiralOrder(matrix, 0, m - 1, 0, n - 1)\n\tdef get_spiralOrder(self, matrix, r_start, r_end, c_start, c_end):\n\t\tif r_start > r_end or c_start > c_end:\n\t\t\treturn []\n\t\telif r_start == r_end:\n\t\t\treturn matrix[r_start][c_start:c_end + 1]\n\t\telif c_start == c_end:\n\t\t\treturn [matrix[j][c_end] for j in range(r_start, r_end + 1)]\n\t\tcurr = matrix[r_start][c_start:c_end + 1] + [matrix[j][c_end] for j in range(r_start + 1, r_end)] +\\\n\t\t\t\tmatrix[r_end][c_start:c_end + 1][::-1] +\\\n\t\t\t\t[matrix[j][c_start] for j in reversed(range(r_start + 1, r_end))]\n\t\tres = curr + self.get_spiralOrder(matrix, r_start + 1, r_end - 1, c_start + 1, c_end - 1)\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.spiralOrder([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]))",
    "language": "python"
  },
  "node_id": "dailycode-6d9dbe9c0db5433dbf81e522dbfedeb0",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470121"
}