Best O(M+N) Solution
Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\nO(m+n) \n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    bool searchMatrix(ve
# Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\n$$O(m+n)$$ \n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target) {\n        int m = matrix.size(), n = matrix[0].size();\n        int i = 0, j = n - 1;\n        while (i < m && j >= 0) {\n            if (matrix[i][j] == target)\n                return true;\n            else if (matrix[i][j] > target)\n                j--;\n            else\n                i++;        \n        }\n        return false;\n    }\n};\n```
['C++']