My 220ms cpp code


  • 0
    L
    class Solution {
    public:
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int m = matrix.size();
        if (m==0) return false;
        int n = matrix[0].size();
        if (n==0) return false;
        int i=0, j=n-1;
        while (i<=m-1&&j>=0){
            if (matrix[i][j]>target) j--;
            else if (matrix[i][j]<target) i++;
            else return true;
        }
        return false;
    }
    };

Log in to reply
 

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