思路与54相同,由于为行=列的数组,再判断何时跳出时可简化步骤。

class Solution {
    public int[][] generateMatrix(int n) {
        int[][] matrix = new int[n][n];
        int u=0,d=n-1,s=1;
        while(d>=u){
            for(int i=u;i<=d;i++)   {matrix[u][i]=s++;}u++;
            for(int i=u;i<=d;i++)    {matrix[i][d]=s++;}//r--;
            for(int i=d-1;i>=u-1;i--)   {matrix[d][i]=s++;}d--;
            for(int i=d;i>=u;i--)   {matrix[i][u-1]=s++;}//l++;
         
        }
        return matrix;
    }
}

leetcode59 spiral matrix2相关推荐

  1. LeetCode59 Spiral Matrix II

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

  2. LeetCode github集合,附CMU大神整理笔记

    Github LeetCode集合 本人所有做过的题目都写在一个java项目中,同步到github中了,算是见证自己的进步.github目前同步的题目是2020-09-17日之后写的题.之前写过的题会 ...

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

  4. LeetCode 54. Spiral Matrix--Python解法--螺旋排序

    题目地址:Spiral Matrix - LeetCode Given a matrix of m x n elements (m rows, n columns), return all eleme ...

  5. Leetcode: Spiral Matrix

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

  6. Spiral Matrix

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

  7. 旋转遍历矩阵 Spiral Matrix

    为什么80%的码农都做不了架构师?>>>    问题: Given a matrix of m x n elements (m rows, n columns), return al ...

  8. LeetCode 59 Spiral Matrix II(螺旋矩阵II)(Array)

    版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5214 ...

  9. LeetCode Spiral Matrix II (生成螺旋矩阵)

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

  10. 59. Spiral Matrix II

    /** 59. Spiral Matrix II * 12.5 by Mingyang* 注意,这里我们说的Matrix就是正方形,不再是长方形了,所以我们会用* 更简单的方法,就是直接上下左右分别加 ...

最新文章

  1. Python的知识点 plt.plot()函数细节
  2. span 可编辑 控制数量_CSS如何限制显示的文本字数
  3. ios中的自动释放池
  4. 全球厂商已向自动驾驶投入800亿美元 依然群龙无首 | 厚势
  5. 第二阶段冲刺第十天,6月9日。
  6. Ubuntu+PHP+Apache+Xdebug 使用方法
  7. el表达式中换行_angularjs/ng-bind如何保留换行符
  8. 解决: service endpoint with name xxx already exists ( docker 已删除的容器却依旧存在)
  9. ASP.NET页面与IIS底层交互和工作原理详解(一)
  10. java 打印制表符_开发简单的Java应用
  11. VMware Fusion for Apple silicon
  12. HC05蓝牙模块与stm32通信
  13. 对于SOAP协议的全面介绍
  14. 手把手教你快速搭建私服环境
  15. 线扫相机DALSA-Image Format(读图格式设置)
  16. python-课后作业-4
  17. 《拥抱机器人时代——Servo杂志中文精华合集》——4.5 审视无线技术
  18. k-d树(Kd trees)
  19. java8通过 poi+text 将word转为pdf
  20. 计算机算法讲解的ppt,算法讲解ppt课件.ppt

热门文章

  1. 基于Vue2的一个人员选择插件
  2. QUIC特性之连接迁移和队头阻塞消除
  3. 大年三十问候导师的后果
  4. 华为路由器怎么配置虚拟服务器,华为路由器配置实例详细备注讲解
  5. 百度经纬度和google经纬度互转
  6. 计算机搜索功能怎么搜内容,怎么让Windows7系统搜索文件内容
  7. a4在html中的尺寸,网页设立A4大小
  8. 【SPSS】重复测量设计方差分析-单因素
  9. 编程为什么有趣?浅谈编程的快乐。
  10. 京东2019校园招聘测试开发工程师面试经历