题目大意:按螺旋顺序填写n*n的二维数组
分析:和leetcode54类似,比它还简单。螺旋填写二维数组即可。
代码:转载自https://blog.csdn.net/u014673347/article/details/48014543
class Solution {
public:
vector<vector<int> > generateMatrix(int n) {
if (n == 0)return vector<vector<int> >();
vector<vector<int> >result(n, vector<int>(n, 0));
int square = n * n;
int num = 1;
int x = 0, y = 0;
while (num <= square) {
while (y < n && result[x][y] == 0) {
result[x][y] = num;