766. Toeplitz Matrix斜对角矩阵
2024-08-28 23:32:02
[抄题]:
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;
}
}
最新文章
- Vmware无法获取快照信息 锁定文件失败
- Win10 Build9926 更新问题解决
- Guid与id区别
- git_2-linux
- applicationContext.xml文件放置位置不同而导致的jUnit测试的时候路径的不同
- VCL ActiveX 播放视频
- InstallShield Clone dialog
- page-object使用(2)---elements
- zoj 2156 - Charlie&;#39;s Change
- UVa10791 - Minimum Sum LCM
- 【LOJ2586】【APIO2018】选圆圈 CDQ分治 扫描线 平衡树
- Druid(新版starter)在SpringBoot下的使用以及优点
- dubbo 面试
- 移动端Web界面滚动touch事件
- 使用FreeRTOS进行性能和运行时分析
- Docker的网络类型和固定IP设置
- 002.HAProxy安装及常见配置
- mysql5.6优化
- 2013 ACM/ICPC 杭州网络赛C题
- ASP .NET SVN &;&; emmet 插件
热门文章
- Python之os.path
- bzoj 4987 Tree
- [Luogu3769][CH弱省胡策R2]TATT
- Django Rest Framework - Could not resolve URL for hyperlinked relationship using view name “user-detail”
- 有返回值的多线程demo
- tomcat部署war包启动后请求无响应,一直报404
- Java 引用类型数组
- css学习笔记之图像
- ror配置unicorn部署
- java代码把字母转换大小写、、、、