摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]思路:这道题顺时针从1到n2放入数组,没啥高深数据结构或算法,直接顺时针打印就可以了。class Solution {public: vector > generateMatrix(int n) { ... 阅读全文
posted @ 2014-04-05 23:09 Awy 阅读(100) 评论(0) 推荐(0) 编辑
摘要: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5].解析:这道题没有什么太过复杂的数据结构的思想,就是顺时针打印矩阵。我们来分析循环结束条件。假设这个矩阵的的行数rows,列数是columns。打印第一圈的左上角的坐标(1,1 阅读全文
posted @ 2014-04-05 21:52 Awy 阅读(171) 评论(0) 推荐(0) 编辑