1.题目描述
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
2.Solutions
1 | public static int[][] generateMatrix(int n) { |
参考:【LeetCode】54. Spiral Matrix