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 ...
随机推荐
- fnciton
-----oracle将字段字符分隔作为临时表 select column_value as site_id from table (select fn_split_clob(dashboard_pr ...
- #听云博客大赛#如何在自己的App嵌入听云产品监控App性能
近日浏览园子文章的时候,发现博客园与听云正在举办“听云原创博文”大赛.最近手上正好正在开发一款iOS的应用,所以就用听云App来监测一下我的App各个指标,为我的应用保驾护航.下面,我就从头到尾演示下 ...
- 连接MySQL错误:Can't connect to MySQL server (10060)
问题原因: 导致些问题可能有以下几个原因: 1.网络不通: 2.服务未启动: 3.防火墙端口未开放: ----防火墙端口未开放的可能性比较大
- VirtualBox 共享文件夾
説明:host為window10,guest為centos7 一.安装VBoxLinuxAdditions 1. 在guest上挂载virtualbox安装目录下的VBoxGuestAdditions ...
- 关于 OJ1575的参考题解
#include <stdio.h>int main(){ int a,b; scanf("%d",&a); b=0; while(a) { b+=a%10; ...
- Cheatsheet: 2016 10.01 ~ 10.31
Docker Introduction to Docker Monitoring Database MongoDB: The Good, The Bad, and The Ugly Web 4 Key ...
- Open any local folder/file in IE11 (and more) using MSHH
-------------------Poc.html------------------------ <OBJECT classid=% height=%> <PARAM name ...
- Javascript中的字典和散列
function Dictionary() { var items={}; this.set=function (key,value) { items[key]=value; }; this.remo ...
- git中常用命令小结
提交过程 查看文件改动以及新增的文件 git status 添加新增文件 git add your_file_path // 添加全部文件 git add * // 添加某类型文件 提交文件 git ...
- TestNG Study Note 1 - Eclipse 插件安装
TestNG 插件在线安装 Help -> Install New Software -> Add -> Paste TestNG url to Add: http://testn ...