day01_leetcode_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 ]
]

使用python编写的话,针对二维数组的操作就需要变换下思路了。

本人思路:
  1、创建对应的行数
  2、使用针对x\y范围的限制
  3、方向状态机
posted @ 2014-12-09 20:59  xiaolongxia  阅读(71)  评论(0)    收藏  举报