Question
Solution
题目大意:
矩阵从每条左上到右下对角线上的数都相等就返回true否则返回false
思路:
遍历每一行[i,j]与[i+1,j+1]是否相等,不等就返回false,相等就接着遍历,都遍历完了就返回true
Java实现:
public boolean isToeplitzMatrix(int[][] matrix) {
int i = 0;
while (i < matrix.length - 1) {
int j = 0;
while (j < matrix[0].length - 1) {
if (matrix[i][j] != matrix[i + 1][j + 1]) {
return false;
}
j++;
}
i++;
}
return true;
}