LeetCode Spiral Matrix
class Solution {
public:
vector<int> spiralOrder(vector<vector<int> > &matrix) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m,n;
int cir;
int i,j;
vector<int> re;
if(matrix.size()==)
return re; m=matrix.size();
n=matrix[].size(); cir=min(m,n);
cir=(cir+)/;
for(i=;i<cir;i++)
{
for(j=i;j<i+n-(i)*;j++)
re.push_back(matrix[i][j]); for(j=i+;j<i++m-(i+)*;j++)
re.push_back(matrix[j][i+n-(i)*-]); if(i++m-(i+)*!=i)
for(j=i+n-(i)*-;j>=i;j--)
re.push_back(matrix[i++m-(i+)*][j]); if(i+n-(i)*-!=i)
for(j=i++m-(i+)*-;j>i;j--)
re.push_back(matrix[j][i]);
}
return re; }
};
LeetCode Spiral Matrix的更多相关文章
- LeetCode: Spiral Matrix II 解题报告-三种方法解决旋转矩阵问题
Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in sp ...
- [LeetCode] Spiral Matrix II 螺旋矩阵之二
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- [LeetCode] Spiral Matrix 螺旋矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- LeetCode:Spiral Matrix I II
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...
- [LeetCode]Spiral Matrix 54
54.Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the ma ...
- LeetCode: Spiral Matrix 解题报告
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix ...
- [Leetcode] spiral matrix ii 螺旋矩阵
Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order. For ...
- LeetCode——Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- [leetcode]Spiral Matrix II @ Python
原题地址:https://oj.leetcode.com/problems/spiral-matrix-ii/ 题意: Given an integer n, generate a square ma ...
- [leetcode]Spiral Matrix @ Python
原题地址:https://oj.leetcode.com/problems/spiral-matrix/ 题意: Given a matrix of m x n elements (m rows, n ...
随机推荐
- HDU2586How far away ?
http://acm.hdu.edu.cn/showproblem.php?pid=2586 How far away ? Time Limit: 2000/1000 MS (Java/Others) ...
- 内置函数callable(object)
如果对象object参数是可以调用的对象,就返回True:否则返回False.不过要注意的是,当一个对象是可以调用的,并不表示调用该对象时执行一定成功,但不可调用的对象去调用时一定不会成功.如果类对象 ...
- Learn GIT
1.创建版本库: git init 设置用户: git config --global user.email "you@example.com" 2.添加到仓库(将修改的内容提交到 ...
- C#解决一个奇怪的,命名空间“XXX”中不存在类型或命名空间名称“xxx”的问题
最近做项目时,引用了一个第三方的程序集,代码层面没有任何语法错误,编译提示:命名空间"System.Net"中不存在类型或命名空间名称"FtpClient".是 ...
- 特殊符号 && 和 ||
一.值为false的情况 如果逻辑对象值为0,-0, null,undefined,false,"",NaN.那么值为false. 二.&& || 的 理解 1.& ...
- validate插件深入学习-01 小白从看透一个插件开始
没有编程基础的的我,即使看了一遍jq文档也不知道怎么写程序,一个新的插件看了也不知道怎么用. 总是想做自己会的,自己不会的永远不去触碰,就永远不会. 都说编程这东西,很多都有很像的地方了,一个语言学通 ...
- 解决yum update失败
1.yum update .yum clean.yum install操作提示 Loaded plugins: fastestmirror, langpacks Loading mirror spee ...
- Mysql notes
1. 数据库操作 database management create database sampleDatabase; --创建数据库sampleDatabase show databases; - ...
- gulp 基本使用
1, gulp 依赖node, 使用gulp 之前,要先安装node. Node 安装完成后,它自带npm. Npm: node package manager 就是node 包管理器. 用过jav ...
- File API 读取上传的文件
1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...