My solution in c++ using STL


  • 0
    R

    class Solution {
    public:

    bool static myfunction (int i,int j) { return (i<j); }
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int n=matrix.size();
        int m=matrix[0].size();
        
        for(int i=0;i<n;i++){
            if(target<= matrix[i][m-1] && target >= matrix[i][0]){
                if(binary_search(matrix[i].begin(),matrix[i].end(),target,myfunction)){
                    return true;
                }
            }
        }
        return false;
        
    }
    

    };


Log in to reply
 

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