Simple Straight Forward Solution without binary search or recursion

  • 0
    class Solution {
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            if(matrix.size()==0 || matrix[0].size()==0)
                return false;
            bool resultBoolean = false;
            int matSize= matrix[0].size();
            for(int i=0; i < matrix.size(); ++i){
                    // search in the ith vector if the target is in there or not
                    for(vector<int>::iterator it= matrix[i].begin(); it!=matrix[i].end(); ++it){
                        if (*it==target){
                            resultBoolean= true;
                    cout << endl;
            return resultBoolean;

Log in to reply

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