Advertisement
SalmaYasser

Untitled

Nov 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class Solution {
  2. public:
  3. bool isToeplitzMatrix(vector<vector<int>>& matrix) {
  4.  
  5. unordered_map <int, int> diagonal_value;
  6.  
  7. int row = matrix.size();
  8.  
  9. if (row == 0) return true;
  10.  
  11. int col = matrix[0].size();
  12.  
  13. for (int i = 0 ; i < row ; i ++ )
  14. {
  15. for (int j = 0 ; j < col ; j ++)
  16. {
  17. if (diagonal_value.find(j - i) == diagonal_value.end())
  18. {
  19. diagonal_value[j - i] = matrix[i][j];
  20. }
  21. else
  22. {
  23. if (diagonal_value[j - i] != matrix[i][j])
  24. return false;
  25. }
  26. }
  27. }
  28. return true;
  29.  
  30. }
  31. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement