[抄题]:

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.

Now given an M x N matrix, return True if and only if the matrix is Toeplitz.

  1. Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
  2. Output: True
  3. Explanation:
  4. 1234
  5. 5123
  6. 9512
  7.  
  8. In the above grid, the diagonals are "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]", and in each diagonal all elements are the same, so the answer is True

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

nums.len是行数,nums[0].len是列数

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

仔细看还是能看出规律的:

[一刷]:

数组中有index+1的情况就应该注意一下上界的范围-1了

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

  1. class Solution {
  2. public boolean isToeplitzMatrix(int[][] matrix) {
  3. //cc
  4. if (matrix == null || matrix[0] == null) {
  5. return false;
  6. }
  7.  
  8. //for loop
  9. for (int i = 0; i < matrix.length - 1; i++) {
  10. for (int j = 0; j < matrix[i].length - 1; j++) {
  11. if (matrix[i + 1][j + 1] != matrix[i][j]) {
  12. return false;
  13. }
  14. }
  15. }
  16.  
  17. //return
  18. return true;
  19. }
  20. }

766. Toeplitz Matrix斜对角矩阵的更多相关文章

  1. 【LEETCODE】45、766. Toeplitz Matrix

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  2. 【Leetcode_easy】766. Toeplitz Matrix

    problem 766. Toeplitz Matrix solution1: class Solution { public: bool isToeplitzMatrix(vector<vec ...

  3. 766. Toeplitz Matrix - LeetCode

    Question 766. Toeplitz Matrix Solution 题目大意: 矩阵从每条左上到右下对角线上的数都相等就返回true否则返回false 思路: 遍历每一行[i,j]与[i+1 ...

  4. LeetCode - 766. Toeplitz Matrix

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...

  5. LeetCode 766 Toeplitz Matrix 解题报告

    题目要求 A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now ...

  6. 766. Toeplitz Matrix

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...

  7. [LeetCode&Python] Problem 766. Toeplitz Matrix

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...

  8. 【LeetCode】766. Toeplitz Matrix 解题报告

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:两两比较 方法二:切片相等 方法三:判断每条 ...

  9. [LeetCode] Toeplitz Matrix 托普利兹矩阵

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...

随机推荐

  1. php 中 用curl 发送 https 请求

    在 php.ini 中修改配置选项 curl.cainfo = "D:\phpStudy\php\php-5.6.27-nts\pert\cacert.pem" 其中 cacert ...

  2. ExpressionTree,Emit,反射

    ExpressionTree,Emit,反射 https://www.cnblogs.com/7tiny/p/9861166.html [前言] 前几日心血来潮想研究着做一个Spring框架,自然地就 ...

  3. hibernate的list和iterate的区别

    一.先介绍一下java中的缓存系统JCS(java cache system)  1.JCS(Java Caching System)是一个对象Cache,它可以把Java对象缓存起来,提高那些访问频 ...

  4. hexo搭建个人主页托管于github

    之前学习了 如何利用Github免费搭建个人主页,今天利用hexo来快速生成个人网页托管于github上. hexo系列教程:(一)hexo介绍 什么是hexo hexo是一个基于Node.js的静态 ...

  5. VS 生成 dll、exe 版本号与SVN版本号一致

    1.VS 可自动生成版本号 注释掉以下两行代码 [assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersi ...

  6. #503. 「LibreOJ β Round」ZQC 的课堂 容斥原理+Treap

    题目: 题解: 比较容易发现 : \(x,y\) 的贡献是独立的. 所以可以分开考虑. 假设我们考虑 \(x\).向量在 \(x\) 方向的投影依次是 : \(\{a_1,a_2, ... ,a_n\ ...

  7. new Date(2016,3,29,10) 时区的问题

    http://my.oschina.net/xinxingegeya/blog/394821http://www.cnblogs.com/qiuyi21/archive/2008/03/04/1089 ...

  8. 如何删除xcode 中过期的描述性文件

    1.使用终端 首先 打开终端 cd ~/Library/MobileDevice/Provisioning\ Profiles/再删除所有 rm *.mobileprovision 2.直接找到文件夹 ...

  9. substr的学习(PHP学习)

    substr的用法: 首先看PHP手册 ,手册上是这样说的 string substr ( string $string , int $start [, int $length ] ) 执行subst ...

  10. php redis 命令合集

    1.https://www.cnblogs.com/aipiaoborensheng/p/5666005.html 2.https://www.cnblogs.com/doanddo/p/734908 ...