[抄题]:

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;
}
}

最新文章

  1. Vmware无法获取快照信息 锁定文件失败
  2. Win10 Build9926 更新问题解决
  3. Guid与id区别
  4. git_2-linux
  5. applicationContext.xml文件放置位置不同而导致的jUnit测试的时候路径的不同
  6. VCL ActiveX 播放视频
  7. InstallShield Clone dialog
  8. page-object使用(2)---elements
  9. zoj 2156 - Charlie&amp;#39;s Change
  10. UVa10791 - Minimum Sum LCM
  11. 【LOJ2586】【APIO2018】选圆圈 CDQ分治 扫描线 平衡树
  12. Druid(新版starter)在SpringBoot下的使用以及优点
  13. dubbo 面试
  14. 移动端Web界面滚动touch事件
  15. 使用FreeRTOS进行性能和运行时分析
  16. Docker的网络类型和固定IP设置
  17. 002.HAProxy安装及常见配置
  18. mysql5.6优化
  19. 2013 ACM/ICPC 杭州网络赛C题
  20. ASP .NET SVN &amp;&amp; emmet 插件

热门文章

  1. Python之os.path
  2. bzoj 4987 Tree
  3. [Luogu3769][CH弱省胡策R2]TATT
  4. Django Rest Framework - Could not resolve URL for hyperlinked relationship using view name “user-detail”
  5. 有返回值的多线程demo
  6. tomcat部署war包启动后请求无响应,一直报404
  7. Java 引用类型数组
  8. css学习笔记之图像
  9. ror配置unicorn部署
  10. java代码把字母转换大小写、、、、