LeetCode 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.
Example 1:
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.
Example 2:
Input: matrix = [[1,2],[2,2]]
Output: False
Explanation:
The diagonal “[1, 2]” has different elements.
Note:
- matrix will be a 2D array of integers.
- matrix will have a number of rows and columns in range [1, 20].
- matrix[i][j] will be integers in range [0, 99].
思路: 只要循环对比即可,思路见代码注释
代码:
class Solution {
public:bool isToeplitzMatrix(vector<vector<int>>& matrix) {int rows = matrix.size();int columns=matrix[0].size();//取矩阵的长宽for (int i = 1; i < rows; ++i){for (int j = 1; j < columns; ++j){if (matrix[i][j] != matrix[i - 1][j - 1]){//对比所有对角线上的数据,如果有不一样就返回falsereturn false;}}}return true;//如果对角线上的数都一样,则结果返回true}
};
结果: 22ms
LeetCode 766. Toeplitz Matrix相关推荐
- [leetcode] 766. Toeplitz Matrix @ python
原题 A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now gi ...
- Leetcode PHP题解--D26 766. Toeplitz Matrix
2019独角兽企业重金招聘Python工程师标准>>> 766. Toeplitz Matrix 题目链接 766. Toeplitz Matrix 题目分析 拓普利兹矩阵,应该不用 ...
- 766. 托普利茨矩阵(javascript)766. Toeplitz Matrix
给你一个 m x n 的矩阵 matrix .如果这个矩阵是托普利茨矩阵,返回 true :否则,返回 false . 如果矩阵上每一条由左上到右下的对角线上的元素都相同,那么这个矩阵是 托普利茨矩阵 ...
- LeetCode 59 Spiral Matrix II(螺旋矩阵II)(Array)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5214 ...
- Toeplitz matrix 与 Circulant matrix
之所以专门定义两个新的概念,在于它们特殊的形式,带来的特别的形式. 1. Toeplitz matrix 对角为常数: n×nn\times n 的矩阵 AA 是 Toepliz 矩阵当且仅当,对于 ...
- LeetCode 73. Set Matrix Zeroes
LeetCode 73. Set Matrix Zeroes Solution1:我的答案 比较笨,算法时间复杂度是O(mn)O(mn)O(mn),占用额外空间是O(m+n)O(m+n)O(m+n) ...
- LeetCode: 868. Transpose Matrix
LeetCode: 868. Transpose Matrix 题目描述 Given a matrix A, return the transpose of A. The transpose of a ...
- C#LeetCode刷题之#766-托普利茨矩阵(Toeplitz Matrix)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3748 访问. 如果一个矩阵的每一方向由左上到右下的对角线上具有相 ...
- leetcode 54. Spiral Matrix | 54. 螺旋矩阵(Java)
题目 https://leetcode.com/problems/spiral-matrix/ 题解 类似于状态机的思路,设定一个 padding,走一圈之后,padding+1 .用 长宽 - pa ...
最新文章
- NVIDIA Jetson NX开发板在U盘挂载的时候出现:error mounting unknown filesystem type ‘exfat‘错误
- 通过crontab调度java -jar任务提示nohup: failed to run command `java': No such file or directory...
- 项目打包部署到Tomcat
- Natasha 4.0 探索之路系列(三) 基本的动态编译
- opengl模板缓冲区
- 添加游戏到游戏浏览器中的小工具
- 论一切都是文件之匿名 inode
- 清除n天以前的日志文件以及mysql-bin文件
- 微信小程序下载图片保存到本地
- gstreamer的rtsp推流(笔记)
- vim命令下显示行号
- 【Android -- 技术周刊】第 021 期
- 一文带你深入了解大数据服务
- 关于轻量级知识共享平台mm-wiki的使用
- 进程调度案例分析:为何不能调度?
- 如何通过网页超链接控制电脑应用程序
- php创建数组教程,PHP中使用array函数新建一个数组
- Vue3中watch和watchEffect监听的用法
- 计算机说课稿模板小学数学,优秀小学数学专用说课模板
- 点列图、横向像差、径向像差、畸变
热门文章
- OpenVINO 2019 R2.0 Custom Layer Implementation for linux(1)
- 【Swin Transformer Block】的整体流程如下:
- 深度残差收缩网络:(五)实验验证
- 解决Vue报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
- RequireJS模块的建立:插件化体验 - demo演示篇
- vue.js项目中,关于element-ui完整引入、按需引入的介绍
- 大图幻灯粉红色bootstrap4引导页模板
- 多城市教育培训机构行业企业站群系统源码-强大的SEO功能-内置三千多个城市
- emlog和typecho文章采集插件-简数第三方数据采集
- 服务器新建文件命令,云服务器中新建文件夹命令