当前位置:网站首页>766. toplitz matrix
766. toplitz matrix
2022-06-28 01:49:00 【Mr Gao】
766. Toplitz matrix
To give you one m x n Matrix matrix . If this matrix is a Toeplitz matrix , return true ; otherwise , return false .
If every diagonal of a matrix from top left to bottom right has the same element , So what is the matrix Toplitz matrix .
Example 1:
Input :matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
Output :true
explain :
In the above matrix , Its diagonal is :
“[9]”, “[5, 5]”, “[1, 1, 1]”, “[2, 2, 2]”, “[3, 3]”, “[4]”.
All the elements on each diagonal are the same , So the answer is True .
Example 2:
Input :matrix = [[1,2],[2,2]]
Output :false
explain :
Diagonals “[1, 2]” The elements on are different .
The solution code is as follows :
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;
}
边栏推荐
猜你喜欢
Original | 2025 to achieve the "five ones" goal! The four products of Jiefang power are officially released
Drug interaction prediction based on learning size adaptive molecular substructure
面试官问:JS的继承
面试官问:能否模拟实现JS的new操作符
Import the data table in MySQL into Excel
Solve storage problems? WMS warehouse management system solution
Deepmind | pre training of molecular property prediction through noise removal
Evaluation - grey correlation analysis
MapReduce elementary programming practice
机器学习笔记 - 时间序列作为特征
随机推荐
205. 同构字符串
Solon 1.8.3 release, cloud native microservice development framework
Is there any risk in opening an account for flush stock? Is it safe for flush to open an account
【牛客討論區】第四章:Redis
Arrays.asList()坑
Adobe Premiere foundation - sound adjustment (volume correction, noise reduction, telephone tone, pitch shifter, parameter equalizer) (XVIII)
Modular development
How to study efficiently
I/O限制进程与CPU限制进程
How to understand query, key and value in transformer
Drug interaction prediction based on learning size adaptive molecular substructure
网络爬虫是什么
Web3 技术初体验以及相关学习资料
数据库的新选择 Amazon Aurora
Capacitor
Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
Deepmind | pre training of molecular property prediction through noise removal
【DNS 解析】将Name.com的域名接入DNSPod解析
数据库查询优化:主从读写分离及常见问题
Esxi based black Qunhui DSM 7.0.1 installation of VMware Tools