Files
2020-08-07 17:06:53 +08:00

30 lines
705 B
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/)
## 题目
Given a positive integer *n*, generate a square matrix filled with elements from 1 to *n*2 in spiral order.
**Example:**
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
## 题目大意
给定一个正整数 n生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。
## 解题思路
- 给出一个数组 n要求输出一个 n * n 的二维数组,里面元素是 1 - n*n且数组排列顺序是螺旋排列的
- 这一题是第 54 题的加强版,没有需要注意的特殊情况,直接模拟即可。