-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path766.cpp
More file actions
28 lines (28 loc) · 762 Bytes
/
Copy path766.cpp
File metadata and controls
28 lines (28 loc) · 762 Bytes
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
class Solution {
public:
bool isToeplitzMatrix(vector<vector<int>>& matrix) {
int n = matrix.size();
if(n == 0)
return true;
int m = matrix[0].size();
for(int i = 0; i < n - 1; ++i) {
int temp = matrix[i][0], j = i + 1,k = 1;
while(j < n && k < m) {
if(matrix[j][k] !=temp)
return false;
++j;
++k;
}
}
for(int i = 1; i < m - 1; ++i) {
int temp = matrix[0][i], j = 1,k = i + 1;
while(j < n && k < m) {
if(matrix[j][k] !=temp)
return false;
++j;
++k;
}
}
return true;
}
};