Short clean solution


  • -1
    M
    class Solution {
    

    public:
    bool searchMatrix(vector<vector<int> > &matrix, int target) {

        int i=matrix.size()-1,j=0;
        
        while(j<matrix[0].size()&&i>=0)
        {
            int x = matrix[i][j];
            if(target==x) return 1;
            if(target>x) j++;
            else i--;
        }
        
        return 0;
        
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.