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的更多相关文章

  1. LeetCode: Spiral Matrix II 解题报告-三种方法解决旋转矩阵问题

    Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in sp ...

  2. [LeetCode] Spiral Matrix II 螺旋矩阵之二

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  3. [LeetCode] Spiral Matrix 螺旋矩阵

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  4. 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 ...

  5. [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 ...

  6. LeetCode: Spiral Matrix 解题报告

    Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix ...

  7. [Leetcode] spiral matrix ii 螺旋矩阵

    Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order. For ...

  8. LeetCode——Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  9. [leetcode]Spiral Matrix II @ Python

    原题地址:https://oj.leetcode.com/problems/spiral-matrix-ii/ 题意: Given an integer n, generate a square ma ...

  10. [leetcode]Spiral Matrix @ Python

    原题地址:https://oj.leetcode.com/problems/spiral-matrix/ 题意: Given a matrix of m x n elements (m rows, n ...

随机推荐

  1. JS跨域

    //2011-7-25 (function(){ //闭包 function load_script(xyUrl, callback){ var head = document.getElements ...

  2. placeholder修改字体和颜色

    textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...

  3. [Machine-Learning] K临近算法-简单例子

    k-临近算法 算法步骤 k 临近算法的伪代码,对位置类别属性的数据集中的每个点依次执行以下操作: 计算已知类别数据集中的每个点与当前点之间的距离: 按照距离递增次序排序: 选取与当前点距离最小的k个点 ...

  4. [OC][转]UITableView属性及方法大全

    Tip: UITableView属性及方法大全  (摘录地址) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 1 ...

  5. Java开发中经典的小实例-(打印输入重复的值)

    import java.util.ArrayList;import java.util.Scanner;public class Test8 {    public static void main( ...

  6. servlet(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  7. 使用spring aspect控制自定义注解

    自定义注解:这里是一个处理异常的注解,当调用方法发生异常时,返回异常信息 /** * ErrorCode: * * @author yangzhenlong * @since 2016/7/21 */ ...

  8. PHP基础算法

    1.首先来画个菱形玩玩,很多人学C时在书上都画过,咱们用PHP画下,画了一半. 思路:多少行for一次,然后在里面空格和星号for一次. <?php for($i=0;$i<=3;$i++ ...

  9. repeater重复器、地址栏传值、response

    repeater重复器: <HeaderTemplate> <ItemTemplate> <AlternatingItemTemplate> <FooterT ...

  10. typedef与#define的区别

    1.  typedef typedef故名思意就是类型定义的意思,但是它并不是定义一个新的类型而是给已有的类型起一个别名,在这一点上与引用的含义类似,引用是变量或对象的别名,而typedef定义的是类 ...