766. Toeplitz Matrix斜对角矩阵
[抄题]:
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斜对角矩阵的更多相关文章
- 【LEETCODE】45、766. Toeplitz Matrix
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【Leetcode_easy】766. Toeplitz Matrix
problem 766. Toeplitz Matrix solution1: class Solution { public: bool isToeplitzMatrix(vector<vec ...
- 766. Toeplitz Matrix - LeetCode
Question 766. Toeplitz Matrix Solution 题目大意: 矩阵从每条左上到右下对角线上的数都相等就返回true否则返回false 思路: 遍历每一行[i,j]与[i+1 ...
- LeetCode - 766. Toeplitz Matrix
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...
- LeetCode 766 Toeplitz Matrix 解题报告
题目要求 A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now ...
- 766. Toeplitz Matrix
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...
- [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 ...
- 【LeetCode】766. Toeplitz Matrix 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:两两比较 方法二:切片相等 方法三:判断每条 ...
- [LeetCode] Toeplitz Matrix 托普利兹矩阵
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...
随机推荐
- [QT][问题记录]发布软件时遇到的问题
2017-3-9 11:22:13 无法定位程序输入点 _ZdaPvj 于动态链接库 libstdc++-6.dll 上. 这是在自己机器上出现的问题. 使用cmd 进行命令 windeployqt ...
- 【eclipse新增系列】eclipse新安装设计编码统一
- bzoj 3124 直径
Written with StackEdit. Description 小\(Q\)最近学习了一些图论知识.根据课本,有如下定义. 树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一 ...
- windows下通过Git Bash使用Git常用命令
Git跟SVN最大不同的地方就是分布式.SVN的集中式与Git的分布式决定各自的业务场景.既然是分布式的,那么大部分操作就是本地操作.一般Git操作都是通过IDE,比如Eclipse,如果装了Git ...
- dubbox部署到jdk1.7环境,启动:java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()
本地用jdk1.8编译的服务提供端war包,部署到环境报错了: INFO: Initializing Spring root WebApplicationContext [16/08/17 05:14 ...
- switch控件的使用
java中: public class MainActivity extends Activity implements OnCheckedChangeListener{ private Switch ...
- ADO连接ACCESS数据库
首先在StdAfx.h中加入 建立连接:(在xxApp文件中) 1 声明变量 2 建立连接 (1) AfxOleInit 初始化 OLE 为应用程序的支持. BOOL AFXAPI AfxOleIn ...
- FPGA论剑
今天走在街上,听到了久违的<光辉岁月>,想起6月30号那天,街边所有的餐厅.小店都在播放beyond的经典之作,那天是香港殿堂级乐队beyond乐队主唱兼吉他手黄家驹先生的忌日.黄家驹先生 ...
- mongodb配置和基本操作
MongoDB3.0新特性WiredTigerMMAPv1可插拔引擎API基于web的可视化管理工具 查看版本号mongod --version启动数据库 mongod --dbpath $dbpat ...
- mysql锁,事务
什么是事务 事务定义了一个服务操作序列,由服务器保证这些操作序列在多个客户并发访问和服务器出现故障情况下的原子性事务的属性 A --redo&undo C --undo I --lock D ...