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