[抄题]:

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. matlab算法转为c语言注意事项

    matlab算法转为c语言后,影响c语言效率的关键在于multiword的产生,基于此会有multiword加减法和乘除法,极大消耗资源,减少甚至消除multiword很重要,需注意的是:算法中尽量减 ...

  2. strftime()和strptime的区别

    strftime()是把时间转成规定格式的字符串 strptime()是把字符串转成时间 转载:http://blog.csdn.net/caimouse/article/details/501986 ...

  3. java的日期加减

    在mysql里面

  4. NIOS EDS最容易出错的地方

    越来越多的人使用NIOS II.毕竟,NIOS II是世界上功能最多的软核处理器. NIOS EDS通常是在装QUARTUS的时候一起装上的.通常我们在用的时候都是以模板建立工程的. 在很多情况下,我 ...

  5. 配置ElasticSearch快捷启动

    在/etc/init.d目录下新建文件elasticsearch #!/bin/sh #chkconfig: 2345 80 05 #description: es #export JAVA_HOME ...

  6. ejs的简单应用

    获取数据 var init = function(){ api.my_bean_list({ },function(datas){ console.log(datas); if (datas.errn ...

  7. PHP面向对象深入研究之【组合模式与装饰模式】

    组合模式 定义:组合模式定义了一个单根继承体系,使具有截然不同职责的集合可以并肩工作. 一个军队的案例, <?php abstract class Unit { // 个体 abstract f ...

  8. SDRAM 之时序收敛(学习了特权老师)

    到现在我还是不太理解SDRAM的时序设置,但是可能蒙对了.(呵呵) 开发环境: quartus II 13.0   板子: DE2 EP2C35F672C6N 时序约束step 1:create cl ...

  9. jQ版大图滚动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 恒创科技 基于openStack云主机

    https://www.henghost.com/cloud-vps.shtml?s=gg&gclid=CKaXuOyr79UCFY-TvQodMJ8BCw