当前位置:网站首页>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;
}
边栏推荐
- Is it safe to open an account online now? Novice is just on the road, ask for the answer
- SQL Server 2016 detailed installation tutorial (with registration code and resources)
- 什么是过孔式导电滑环?
- 手机股票开户安全吗,买股票在哪开户?
- 零基础多图详解图神经网络
- LMSOC:一种对社会敏感的预训练方法
- 药物发现综述-01-药物发现概述
- DeepMind | 通过去噪来进行分子性质预测的预训练
- Solve storage problems? WMS warehouse management system solution
- How about the market application strength of large-size conductive slip rings
猜你喜欢
随机推荐
centos8-操作记录-命令版-yum-redis-mysql-nacos-jdk
PostgreSQL setting auto increment field
Zhang Fan: the attribution of flying pig after advertising based on causal inference technology
Set collection usage
【嵌入式基础】串口通信
I/O限制进程与CPU限制进程
golang 猴子吃桃子,求第一天桃子的数量
Transformer论文逐段精读
[DNS resolution] set the name DNSPod resolution for domain name access of COM
Qu'est - ce que la numérisation? Qu'est - ce que la transformation numérique? Pourquoi les entreprises choisissent - elles la transformation numérique?
数据人面试指南 | 准备好这几点做到有备无患!
Data analysts too hot? Monthly income 3W? Tell you the true situation of this industry with data
想开户买股票,在网上办理股票开户安全吗?
Supervised, unsupervised and semi supervised learning
Huawei partners and Developers Conference 2022 | Kirin software cooperates with Huawei to jointly build the computing industry and create a digital intelligence future
Squid proxy server (Web cache layer for cache acceleration)
Can you open an account for stock trading in flush? Is it safe?
信息学奥赛一本通 1359:围成面积
Web mouse click special effects case collection (red heart in live broadcast room)
Golang monkeys eat peaches and ask for the number of peaches on the first day