Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isToeplitzMatrix(vector<vector<int>>& matrix) {
- unordered_map <int, int> diagonal_value;
- int row = matrix.size();
- if (row == 0) return true;
- int col = matrix[0].size();
- for (int i = 0 ; i < row ; i ++ )
- {
- for (int j = 0 ; j < col ; j ++)
- {
- if (diagonal_value.find(j - i) == diagonal_value.end())
- {
- diagonal_value[j - i] = matrix[i][j];
- }
- else
- {
- if (diagonal_value[j - i] != matrix[i][j])
- return false;
- }
- }
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement