https://leetcode-cn.com/problems/toeplitz-matrix/
如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵。
给定一个 M x N
的矩阵,当且仅当它是托普利茨矩阵时返回 True
。
class Solution {
public static boolean isToeplitzMatrix(int[][] matrix) {
int x = matrix.length;
int y = matrix[0].length;
if(x == 0){
return true;
}
for (int i = 1; i < x; i++) {
for (int j = 1; j < y ; j++) {
if( matrix[i][j] != matrix[i-1][j-1])
{
return false;
}
}
}
return true;
}
public static void main(String[] args) {
int [][]a = {{1,2},{2,2}};
System.out.println(isToeplitzMatrix(a));
}
}