当前位置:网站首页>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;
}
边栏推荐
- How to read a paper
- DeepMind | 通过去噪来进行分子性质预测的预训练
- Arrays.asList()坑
- 如何高效读书学习
- Ten thousand words long article understanding business intelligence (BI) | recommended collection
- Maimai hot post: Why are big factories keen on making wheels?
- Solon 1.8.3 发布,云原生微服务开发框架
- Overview and construction of redis master-slave replication, sentinel mode and cluster
- 大尺寸导电滑环市场应用强度如何
- Web mouse click special effects case collection (red heart in live broadcast room)
猜你喜欢

Electron window background transparent borderless (can be used to start the page)

Solon 1.8.3 release, cloud native microservice development framework

零基础多图详解图神经网络

什么是过孔式导电滑环?

单晶炉导电滑环的应用范围和作用是什么

基于可学习尺寸自适应分子亚结构的药物相互作用预测

什么是数字化?什么是数字化转型?为什么企业选择数字化转型?

MySQL十种锁,一篇文章带你全解析

如何在您的Shopify商店中添加实时聊天功能?

Proe/creo product structure design - continuous research
随机推荐
[untitled]
评价——灰色关联分析
Supervised, unsupervised and semi supervised learning
.mp4视频测试地址
Form forms and form elements (input, select, textarea, etc.)
国外LEAD赚钱的一些习惯
零基礎多圖詳解圖神經網絡
[open source] open source system sorting - Examination Questionnaire, etc
Golang monkeys eat peaches and ask for the number of peaches on the first day
lodash实现防抖和节流功能及原生实现
电商转化率这么抽象,到底是个啥?
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)
如何阅读一篇论文
Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
有监督、无监督与半监督学习
AI+临床试验患者招募|Massive Bio完成900万美元A轮融资
Transformer论文逐段精读
Can you open an account for stock trading in flush? Is it safe?
awk注意的几个问题
Is there any risk in opening an account for flush stock? Is it safe for flush to open an account