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 ...
随机推荐
- EF事务嵌套
EF中采用的是数据上下文DbContext,当针对数据库的所有操作共用一个数据上下文的时候,会使用同一个连接对象,因此连接打开一次,最后Save的时候关闭连接,避免了频繁的创建连接对象打开关闭,这在一 ...
- Windows 版本的iTunes 修改iPhone的备份路径
帮朋友解决修改iPhone的备份路径问题,故写篇博客整理记录一下. 所需工具 Junction工具 下载该工具然后将文件放到C:\Windows 目录下,如下图: 找到iTunes的备份路径 Wind ...
- 关于AJAX 的交互模型、交互流程及代码示范
AJAX = 异步JavaScript + XML. 它是一种用于创建快速动态网页的技术.通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的情况 ...
- WinSCP无法连接 ubuntu 的解决方法
ubuntu默认不安装sshd服务 需要sudo apt-get install ssh 你可以在ubuntu本机ssh localhost测试是否成功安装了ssh 因为WinSCP是基于ssh的sf ...
- REVERSE
REVERSE函数,刚刚接触,这是一个Oracle和MS Sql都能用的,不知道是不是T-SQL标准的函数,反正能用,挺好 SELECT REVERSE('abcd') 结果为dcba,就是把字符串反 ...
- 【转】使用:after清除浮动
以前总是加一个<div sytle="clear:both"></div>来解决,但这样会增加无语义的标签,下面是用after伪类实现,兼容多种浏览器.cl ...
- lseek函数
所有打开的文件都有一个当前文件偏移量(current file offset),以下简称为 cfo.cfo 通常是一个非负整数,用于表明文件开始处到文件当前位置的字节数.读写操作通常开始于 cfo,并 ...
- LINUX下编译源码时所需提前安装的常用依赖包列表
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-deve ...
- 《与小卡特一起学Python》 Code6 注释
"""这是一个包括多行的注释, 使用了三重引号字符串. 这不完全是注释,不过也可以相当于注释. """ #***************** ...
- HTML meta锚点跳转 小tips
小tips meta锚点跳转 http://www.zhangxinxu.com/wordpress/2015/03/meta-http-equiv-refresh-content/