LeetCode: Spiral Matrix II
来源:互联网 发布:与运算java 编辑:程序博客网 时间:2024/05/22 11:36
思路:好吧,这个题目是很容易的,也是本人到目前为止做的最快的一个题目了(T_T!编程已经成渣了,看看还能不能救)注意临时变量定义的位置,及时清空,或者就在药用的时候定义都可以。
class Solution {public: vector<vector<int>> generateMatrix(int n) {vector<vector<int>> S;int **ret = new int*[n];for(int i=0;i<n;i++) ret[i] = new int[n];int number = 0;int ground = n/2;for(int k = 0;k<ground;k++){for(int j = k;j<n-k;j++)ret[k][j] = ++number;for(int i = k+1;i<n-k-1;i++)ret[i][n-k-1] = ++number;for(int j = n-k-1;j >= k;j--)ret[n-k-1][j] = ++number;for(int i=n-k-2;i>k;i--)ret[i][k] = ++number;}if(n%2){ret[n/2][n/2] = ++number;}for(int i = 0;i<n;i++){ vector<int> temp;for(int j=0;j<n;j++){temp.push_back(ret[i][j]);//cout<<ret[i][j]<<" ";}S.push_back(temp);//cout<<endl;}return S;}};
0 0
- LeetCode: Spiral Matrix II
- LeetCode Spiral Matrix II
- [Leetcode] Spiral Matrix II
- LeetCode : Spiral Matrix II
- [LeetCode] Spiral Matrix II
- [LeetCode]Spiral Matrix II
- [leetcode]Spiral Matrix II
- LeetCode-Spiral Matrix II
- [leetcode] Spiral Matrix II
- LeetCode - Spiral Matrix II
- Leetcode: Spiral Matrix II
- 【LeetCode】Spiral Matrix II
- Leetcode Spiral Matrix II
- [LeetCode] Spiral Matrix II
- LeetCode | Spiral Matrix II
- LeetCode Spiral Matrix II
- Leetcode: Spiral Matrix II
- Spiral Matrix II -- LeetCode
- 解决PKIX:unable to find valid certification path to requested target 的问题
- strtok函数详解
- Snappy(Google家用的快速压缩算法,以前的Zippy)
- IOS GCD的介绍及使用举例&GCD优先级改变、after、group、barrier、sync、apply、semaphore、once等操作方法
- 我的setContentView应该放在何处
- LeetCode: Spiral Matrix II
- FMC编辑框用法
- 基于JavaScript的三种声明全局变量方式介绍
- java 修饰符
- 分布式与集群的区别
- ELF文件结构
- hibernate重点(一) 一对多关系之单向多对一
- android webview
- 当前不会命中断点 此位置当前尚未加载可执行代码