My solution with nomal method


  • 0
    V
    class Solution {
    public:
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            int row = 0;
            for( ; row < matrix.size(); row++ )
                if( matrix[ row ][ 0 ] > target )
                    break;
    
            if( --row < 0 )
                return false;
            
            for( int n : matrix[ row ] )
                if( n == target )
                    return true;
        
            return false;
        }
    };

Log in to reply
 

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