Advertisement
nikunjsoni

240

May 14th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool searchMatrix(vector<vector<int>>& matrix, int target) {
  4.         int rows = matrix.size(), cols = matrix[0].size();
  5.         int curX = rows-1, curY = 0;
  6.        
  7.         while(curX >= 0 && curY < cols){
  8.             int curr = matrix[curX][curY];
  9.             if(curr == target)
  10.                 return true;
  11.             else if(curr > target)
  12.                 curX--;
  13.             else
  14.                 curY++;
  15.         }
  16.         return false;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement