forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_766.java
40 lines (38 loc) · 1.17 KB
/
_766.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.fishercoder.solutions;
public class _766 {
public static class Solution1 {
public boolean isToeplitzMatrix(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
int i = 0;
int j = 0;
int sameVal = matrix[i][j];
while (++i < m && ++j < n) {
if (matrix[i][j] != sameVal) {
return false;
}
}
for (i = 1, j = 0; i < m; i++) {
int tmpI = i;
int tmpJ = j;
sameVal = matrix[i][j];
while (++tmpI < m && ++tmpJ < n) {
if (matrix[tmpI][tmpJ] != sameVal) {
return false;
}
}
}
for (i = 0, j = 1; j < n; j++) {
int tmpJ = j;
int tmpI = i;
sameVal = matrix[tmpI][tmpJ];
while (++tmpI < m && ++tmpJ < n) {
if (matrix[tmpI][tmpJ] != sameVal) {
return false;
}
}
}
return true;
}
}
}