标签:style blog color java strong for ar 代码
题目:
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
For example,
Given n = 3
,
[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]
题解:
这道题跟Spiral Matrix想法也是类似的,就是依照矩阵从外圈到内圈建立。
要考虑如果是奇数行列的话,最中心的那个点要单加。
代码如下:
Reference:leetcodenotes.wordpress.com/2013/11/23/leetcode-spiral-matrix-%E6%8A%8A%E4%B8%80%E4%B8%AA2d-matrix%E7%94%A8%E8%9E%BA%E6%97%8B%E6%96%B9%E5%BC%8F%E6%89%93%E5%8D%B0/
Spiral Matrix II leetcode java,布布扣,bubuko.com
Spiral Matrix II leetcode java
标签:style blog color java strong for ar 代码
原文地址:http://www.cnblogs.com/springfor/p/3887900.html