1
class Solution {
2
public boolean isToeplitzMatrix(int[][] matrix) {
3

4
int n = matrix.length;
5
int m = matrix[0].length;
6

7
for (int i = 0; i < m; i++) {
8
int row = 0;
9
int col = i;
10
int e = matrix[row++][col++];
11
while (row < n && col < m) {
12
if (e == matrix[row][col]) {
13
row++;
14
col++;
15
} else {
16
return false;
17
}
18
}
19
}
20

21
for (int r = 1; r < n; r++) {
22
int row = r;
23
int col = 0;
24
int e = matrix[row++][col++];
25
while (row < n && col < m) {
26
if (e == matrix[row][col]) {
27
row++;
28
col++;
29
} else {
30
return false;
31
}
32
}
33
}
34

35
return true;
36
}
37
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0