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 ]
]
» Solve this problem
This problem has nothing very special, only if you can figure out the regularity of how index changes of the matrix.
I set many counters to calculate.
Sunday, June 16, 2013
Subscribe to:
Post Comments (Atom)
Leetcode 316. Remove Duplicate Letters
这道题表面问的是如何删除重复,实际在问如何从多个字符选取一个保留,从而让整个字符串按升序排列。那么策略就是对于高顺位的字符比如‘a',就要选靠前位置的保留,而低顺位字符如’z'则应该尽量选取靠后位置保留。 算法大概思路:每看到一个字符,我们要决定是否保留 1. ...
-
首先声明一下,这里的面试题主要所指数据结构和算法的题目,题目的分析集中在Leetcode上面的题目上。 我认为一道面试题由以下几个方面组成的 Question Data structure in question Data structure in solutio...
-
Given an array A of integer with size of n( means n books and number of pages of each book) and k people to copy the book. You must distribu...
-
1166. Design File System Medium 62 4 Add to List Share You are asked to design a file system which provides two functions: crea...
No comments:
Post a Comment