mycode

思路:这种方格图一定要预先设置定位的变量,例如最大的长、宽,变化中的长、宽,在while循环中也要不断判断是否满足break条件

class Solution(object):
def spiralOrder(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: List[int]
"""
m = len(matrix)
if m == : return [] # []
n = len(matrix[])
if n == : return [] #[[],[]]
m = m - ; n = n -
r ,l = ,
res = []
#当r == n的时候,也还是要循环
while r <= n and l <= m:
for i in range(r,n+):
res.append(matrix[l][i])
l = l +
if l > m : break
for i in range(l,m+):
res.append(matrix[i][n])
n = n - ; i = n
if n < r : break
while i >= r:
res.append(matrix[m][i])
i -=
m = m - ; i = m
if m < l : break
while i >= l:
res.append(matrix[i][r])
i -=
r +=
return res

leetcode-hard-array-54. Spiral Matrix-NO的更多相关文章

  1. Leetcode 54. Spiral Matrix & 59. Spiral Matrix II

    54. Spiral Matrix [Medium] Description Given a matrix of m x n elements (m rows, n columns), return ...

  2. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

  3. LeetCode - 54. Spiral Matrix

    54. Spiral Matrix Problem's Link ------------------------------------------------------------------- ...

  4. leetcode 54. Spiral Matrix 、59. Spiral Matrix II

    54题是把二维数组安卓螺旋的顺序进行打印,59题是把1到n平方的数字按照螺旋的顺序进行放置 54. Spiral Matrix start表示的是每次一圈的开始,每次开始其实就是从(0,0).(1,1 ...

  5. Leetcode 54:Spiral Matrix 螺旋矩阵

    54:Spiral Matrix 螺旋矩阵 Given a matrix of m x n elements (m rows, n columns), return all elements of t ...

  6. [array] leetcode - 54. Spiral Matrix - Medium

    leetcode-54. Spiral Matrix - Medium descrition GGiven a matrix of m x n elements (m rows, n columns) ...

  7. leetCode 54.Spiral Matrix(螺旋矩阵) 解题思路和方法

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

  8. LeetCode(59)SPiral Matrix II

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

  9. LeetCode 54. Spiral Matrix(螺旋矩阵)

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

  10. 【一天一道LeetCode】#54. Spiral Matrix

    一天一道LeetCode系列 (一)题目 Given a matrix of m x n elements (m rows, n columns), return all elements of th ...

随机推荐

  1. SAP模块一句话入门(专业术语的理解)

    SAP模块一句话入门(专业术语的理解) SAP一句话入门:Financial & Controlling Accounting (FICO) 财务,财务,呵呵,让我们关心一下给我发工资的部门. ...

  2. vue实现登录路由拦截

    第一步 在router.js里面 把需要判断是否登录的路由添加meta对象属性 在meta对象里面自定义一个属性值 第二步 : 在router.js里面 与const router = new Rou ...

  3. 多线程编程-- part5 锁的种类以及辨析

    java中的锁,可以分为同步锁和JUC包中的锁. 同步锁 通过synchronized关键字进行同步,实现对竞争资源的互斥访问的锁,. 原理:对于每一个对象,有且只有一个同步锁,在同一时间点,所有的线 ...

  4. win7下CodeIgniter安装

    一.CodeIgniter是什么 CodeIgniter 是一套给 PHP 网站开发者使用的应用程序开发框架和工具包. 它的目标是让你能够更快速的开发,它提供了日常任务中所需的大量类库, 以及简单的接 ...

  5. wampserver2.2 在window2003下的安装的主要问题

    准备安装最新的wampserver 2.2c,   1.安装问题,安装完成后总是无法启动服务   系统事件中提示错误 找不到附属汇编 Microsoft.VC90.CRT,上一个错误是 参照的汇编没有 ...

  6. 网络初级篇之STP(概念原理)

    一.什么是STP 生成树协议(Spanning Tree Protocol,STP),是一种工作在OSI网络模型中的第二层(数据链路层)的通信协议,基本应用是防止交换机冗余链路产生的环路.用于确保以太 ...

  7. Java GUI :Hello World

    public class Demo01 extends Frame{ public Demo01(){ super("Demo01");//标题 this.setSize(450, ...

  8. IView 给Submenu增加click事件失效解决方案

    在浏览器中,打开开发者选项(F12) 找出对应的class,给其添加一个点击事件,就可以了. 具体的  document  操作,看这里 ----> https://www.cnblogs.co ...

  9. 胡昊—第6次作业—static关键字、对象

    #题目1:编写一个类Computer,类中含有一个求n的阶乘的方法.将该类打包,并在另一包中的Java文件App.java中引入包,在主类中定义Computer类的对象,调用求n的阶乘的方法(n值由参 ...

  10. C# WinForm捕获全局异常(捕获未处理的异常)

    static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...