feat: 2025-10-24打卡
This commit is contained in:
38
766.toeplitz-matrix.java
Normal file
38
766.toeplitz-matrix.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @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
|
||||
|
||||
Reference in New Issue
Block a user