LeetCode p59 Spiral Matrix II 题解
1.题目:
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,返回n*n的数组,内容是1-n的螺旋排列。
2.解题思路:
见代码TUT。。暴力了一波。
3.代码
1 |
|