[抄题]:

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.

Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
Output: True
Explanation:
1234
5123
9512 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给出的题目变变变]:

[代码风格] :

class Solution {
public boolean isToeplitzMatrix(int[][] matrix) {
//cc
if (matrix == null || matrix[0] == null) {
return false;
} //for loop
for (int i = 0; i < matrix.length - 1; i++) {
for (int j = 0; j < matrix[i].length - 1; j++) {
if (matrix[i + 1][j + 1] != matrix[i][j]) {
return false;
}
}
} //return
return true;
}
}

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. boost 部分编译

    完整编译boost库需要很长时间,而且我们不一定会用到所有的库. 那么如何只编译只需要的库呢? 解压boost源码,进入解压后的目录 ./bootstrap.sh生成bjam ./bjam --bui ...

  2. bzoj 2282 消防

    Written with StackEdit. Description 某个国家有\(n\)个城市,这\(n\)个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为\(z_i(z_i ...

  3. 数据库模式显示的Swing表格

    http://code.google.com/p/simpleframework/ 是一个国内开源的JavaWeb框架,但其net.simpleframework.swing包里面提供了一个超强的Sw ...

  4. LOJ10050 The XOR Largest Pair

    题意 在给定的 \(N\) 个整数 \(A_1,A_2,-,A_N\) 中选出两个进行异或运算,得到的结果最大是多少? 对于 \(100\%\) 的数据,\(1\le N\le 10^5, 0\le ...

  5. ubantu 虚拟机无法查看windows共享目录

    初学linux,安装好虚拟机,安装好ubantu系统,启动系统后无法查看windows共享目录. 原因是没有安装 vmware tools 教程地址:http://www.linuxidc.com/L ...

  6. 加载rocksdb实例报错:java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\librocksdbjni3696928169151614297.dll

    项目的缓存中用到了rocksdb,实例化时报错了: Related cause: org.springframework.beans.factory.BeanCreationException: Er ...

  7. XMemcached使用经历

    XMemcached就是Memcached的java客户端之一,目前项目里用到了.据说它比起其他的java客户端从性能上要好一点,实现方式是NIO的.先看怎么实例化出来一个Memcached客户端吧: ...

  8. Jvm垃圾回收器详细

    1, 串行回收器 1.1, 新生代串行回收器 (1)特点:  –它仅仅使用单线程进行垃圾回收  –它是独占式的垃圾回收  –进行垃圾回收时, Java应用程序中的线程都需要暂停(Stop-The-Wo ...

  9. redis的安装和类型及基本命令

    一.memcached和redis区别 1. redis 可以存储,memcached用来缓存, 2. 数据类型,memcached只有string:redis有string,链表,哈希结构,集合,有 ...

  10. FPGA层次结构和复位策略

    FPGA设计中,层次结构设计和复位策略影响着FPGA的时序.在高速设计时,合理的层次结构设计与正确的复位策略可以优化时序,提高运行频率. 设计中,合理的层次结构是我们所追求的. 划分时,按照逻辑分区将 ...