LeetCode题目:Spiral Matrix II
原题地址:https://leetcode.com/problems/spiral-matrix-ii/
class Solution {
public:
vector<vector<int>> generateMatrix(int n) {
if( == n){
vector<vector<int>> coll;
return coll;
}
vector<vector<int>> coll(n, vector<int>(n, ));
int num = ;
for(int i = ; i < n - ; ++i){
for(int j = i; j < n - i; ++j)
coll[i][j] = num++;
for(int j = i + ; j < n - i; ++j)
coll[j][n - i -] = num++;
for(int j = n - i - ; j >= i; --j)
coll[n - i - ][j] = num++;
for(int j = n - i - ; j >= i + ; --j)
coll[j][i] = num++;
}
return coll;
}
};
LeetCode题目:Spiral Matrix II的更多相关文章
- [LeetCode] 59. Spiral Matrix II 螺旋矩阵 II
Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order. For ...
- 【leetcode】Spiral Matrix II
Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 to n2 in s ...
- Java for LeetCode 059 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- LeetCode: 59. Spiral Matrix II(Medium)
1. 原题链接 https://leetcode.com/problems/spiral-matrix-ii/description/ 2. 题目要求 给定一个正整数n,求出从1到n平方的螺旋矩阵.例 ...
- 【leetcode】Spiral Matrix II (middle)
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- Leetcode#59 Spiral Matrix II
原题地址 相比于Spiral Matrix(参见这篇文章)要简单一些,因为是方阵,所以代码简洁一些. 注意当n是奇数的时候,中心小块要单独赋值(代码21行) 代码: vector<vector& ...
- LeetCode 59. Spiral Matrix II (螺旋矩阵之二)
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- LeetCode 58 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- [leetcode]59. Spiral Matrix II螺旋遍历矩阵2
Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 in spiral or ...
随机推荐
- nodejs获取ASP.Net WebAPI(IIS Windows验证)
处理了很多天,终于使用Nodejs可以发出请求至WebAPI,能够正常处理数据了 首先加入npm包 npm install httpntlm 在app.js中加入代码 var httpntlm = r ...
- IActionResult
- php中parse_url函数的源码及分析
前言 看师傅们的文章时发现,parse_url出现的次数较多,单纯parse_url解析漏洞的考题也有很多,在此研究一下源码(太菜了看不懂,待日后再补充Orz) 源码 PHPAPI php_url * ...
- 使用IIFE(立即执行函数)让变量私有化
今天去看了一个GITHUB上的开源项目,在客户端JS的脚本编写的时候,代码中多次使用了IIFE. 一开始我是懵逼的,不知道这种函数的意义何在,小菜鸟嘛. 后面我去研究了一番.发现了它的主要作用就是:让 ...
- RPD Volume 172 Issue 1-3 December 2016 评论02
Introduction to the special issue of Radiation Protection Dosimetry This special issue is a collecti ...
- 谜题22:URL的愚弄
本谜题利用了Java编程语言中一个很少被人了解的特性.请考虑下面的程序将会做些什么? public class BrowserTest { public static void main(String ...
- 输入格式CombineFileInput
此输入格式的作用就是可以将来自多个不同文件的物理块作为一个split,然后由一个map进行处理. http://www.blogjava.net/shenh062326/archive/2012/07 ...
- Eclipse / Pycharm | 使用过程中的一些问题笔记
最近有比较多的用到这两款工具,其中也遇到一些问题,知道了一些快捷键 快捷键什么的这里就不讲了,去网上搜搜,经常使用下,自然就熟悉了 主要记录一下我遇到的几个问题 文章目录 Pycharm出现的部分快捷 ...
- inline-block 前世今生(转)
曾几何时,display:inline-block 已经深入「大街小巷」,随处可见 「display:inline-block; *display:inline; *zoom:1; 」这样的代码.如今 ...
- ThinkPHP处理海量数据分表机制详细代码及说明
ThinkPHP处理海量数据分表机制详细代码及说明 应用ThinkPHP内置的分表算法处理百万级用户数据. 数据表: house_member_0 house_member_1 house_mem ...