59. Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
For example,
Given n = 3,
You should return the following matrix:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
题意:
给定一个整数n,生成一个以1到n的平方根为螺旋顺序元素的螺旋矩阵。
思路:
主要参照54. Spiral Matrix方法二。
1 | class Solution { |
Java Code
1 | class Solution { |