当前位置:网站首页>766. 托普利茨矩阵
766. 托普利茨矩阵
2022-06-27 23:12:00 【Mr Gao】
766. 托普利茨矩阵
给你一个 m x n 的矩阵 matrix 。如果这个矩阵是托普利茨矩阵,返回 true ;否则,返回 false 。
如果矩阵上每一条由左上到右下的对角线上的元素都相同,那么这个矩阵是 托普利茨矩阵 。
示例 1:
输入:matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
输出:true
解释:
在上述矩阵中, 其对角线为:
“[9]”, “[5, 5]”, “[1, 1, 1]”, “[2, 2, 2]”, “[3, 3]”, “[4]”。
各条对角线上的所有元素均相同, 因此答案是 True 。
示例 2:
输入:matrix = [[1,2],[2,2]]
输出:false
解释:
对角线 “[1, 2]” 上的元素不同。
解题代码如下:
bool isToeplitzMatrix(int** matrix, int matrixSize, int* matrixColSize){
int i;
int n=matrixSize;
int m=matrixColSize[0];
printf("%d %d",n,m);
for(i=0;i<m;i++){
int a=matrix[0][i];
int x=0;
int y=i;
while(x+1<n&&y+1<m){
x=x+1;
y=y+1;
if(matrix[x][y]!=a){
return false;
}
}
}
for(i=0;i<n;i++){
int a=matrix[i][0];
int x=i;
int y=0;
while(x+1<n&&y+1<m){
x=x+1;
y=y+1;
if(matrix[x][y]!=a){
return false;
}
}
}
return true;
}
边栏推荐
- 零基礎多圖詳解圖神經網絡
- 单晶炉导电滑环的应用范围和作用是什么
- PostgreSQL setting auto increment field
- SQL Server 2016 detailed installation tutorial (with registration code and resources)
- 9. Openfeign service interface call
- 【嵌入式基础】串口通信
- Is it safe to open a stock account online now? Select a listed securities firm, and the fastest time to open an account is 8 minutes
- Ten thousand words long article understanding business intelligence (BI) | recommended collection
- Redis configuration and optimization of NoSQL
- Informatics Olympiad all in one 1359: enclosed area
猜你喜欢

【说明】Jmeter乱码的解决方法
![完全二叉树的节点个数[非O(n)求法 -> 抽象二分]](/img/56/768f8be9f70bf751f176e40cbb1df2.png)
完全二叉树的节点个数[非O(n)求法 -> 抽象二分]

MapReduce elementary programming practice

Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)

Overview of drug discovery-01 overview of drug discovery

Neural network of zero basis multi map detailed map

FB、WhatsApp群发消息在2022年到底有多热门?

Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)

N methods of data De duplication using SQL

Solve storage problems? WMS warehouse management system solution
随机推荐
centos8-操作记录-命令版-yum-redis-mysql-nacos-jdk
美团动态线程池实践思路已开源
Lodash realizes anti shake and throttling functions and native implementation
Neural network of zero basis multi map detailed map
Which securities speculation account opening commission is the cheapest and safest
信息学奥赛一本通 1359:围成面积
Implementation of timed tasks in laravel framework
Want to open an account to buy stock, is it safe to open an account on the Internet?
Is it safe for Xiaobai in the stock market to open an account on the Internet?
Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
Drug interaction prediction based on learning size adaptive molecular substructure
Is it safe to open an account online now? Novice is just on the road, ask for the answer
Some habits of making money in foreign lead
golang 猴子吃桃子,求第一天桃子的数量
[open source] open source system sorting - Examination Questionnaire, etc
药物发现综述-03-分子设计与优化
Arrays. Aslist() pit
What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?
AI+临床试验患者招募|Massive Bio完成900万美元A轮融资
The research group of Xuyong and duanwenhui of Tsinghua University has developed an efficient and accurate first principles electronic structure deep learning method and program