39 lines
864 B
Java
39 lines
864 B
Java
/*
|
|
* @lc app=leetcode id=766 lang=java
|
|
*
|
|
* [766] Toeplitz Matrix
|
|
*/
|
|
|
|
// @lc code=start
|
|
class Solution {
|
|
public boolean isToeplitzMatrix(int[][] matrix) {
|
|
for(int i=0; i<matrix.length; i++) {
|
|
if(!sameElementsLTRP(matrix, i, 0)) {
|
|
return false;
|
|
}
|
|
}
|
|
for(int j = 0; j<matrix[0].length; j++) {
|
|
if(!sameElementsLTRP(matrix, 0, j)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private boolean sameElementsLTRP(int[][] matrix, int i, int j) {
|
|
int e = matrix[i][j];
|
|
boolean f = true;
|
|
while(i < matrix.length && j < matrix[0].length) {
|
|
if(matrix[i][j] != e) {
|
|
f = false;
|
|
break;
|
|
}
|
|
i++;
|
|
j++;
|
|
}
|
|
return f;
|
|
}
|
|
}
|
|
// @lc code=end
|
|
|