O(M+N) C++ solution
O(M+N) C++ solution for M*N matrix;\n\n    bool searchMatrix(vector>& matrix, int target) {\n       if(matrix.size() == 0) return false;\n        int n = matrix
O(M+N) C++ solution for M*N matrix;\n\n    bool searchMatrix(vector<vector<int>>& matrix, int target) {\n       if(matrix.size() == 0) return false;\n        int n = matrix[0].size()-1;\n        int m = 0;\n        while(m < matrix.size() && n >= 0) {\n            if (matrix[m][n] == target) return true;\n            else if (matrix[m][n] < target) ++m;\n            else --n;\n        }\n        return false;\n    }\n\nThe idea is: \nstart from the upper right corner: \n\n - if the element is equal to target, return true;\n - if the element is greater than target, that means the whole column is greater than target, we can delete a whole column\n - else, we can delete a whole row
[]