✅|O(m+n)|Easy|Explanation
Approach\n Describe your approach to solving the problem. \nThere are two points from where we can start searching i.e - \n1) From top right corner\n2) From bot
# Approach\n<!-- Describe your approach to solving the problem. -->\nThere are two points from where we can start searching i.e - \n1) From top right corner\n2) From bottom left corner\nIn this approach, I have explained throung top right corner, take a Starting position to top right corner value of matrix and compare if(position == target) return true, \nor if(position < target) then jump to the position to next row of same column because the values below our position can caontains target vcalue;\nor if(position > target) then jump to previous column of same row as only the values to the left of position can contains target value.\nRepeat until you reach last row or first column.\n\n![Screenshot (501).png](https://assets.leetcode.com/users/images/4ce363ab-c62f-4597-8104-bd640c8d09dc_1684795370.9902685.png)\n\n# Complexity\n- Time complexity: <b>O(n+m)</b>\n- Auxillary Space complexity: <b>O(1)</b>\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public boolean searchMatrix(int[][] matrix, int target) {\n        int n = matrix.length;\n        int m = matrix[0].length;\n        int row = 0;\n        int col = m-1;\n        while(row < n && col >= 0)\n        {\n            if(matrix[row][col] == target) return true;\n            else if(matrix[row][col] < target) row++;\n            else    col--;\n        }\n        return false;\n    }\n}\n```
['Binary Search', 'Divide and Conquer', 'Greedy', 'Matrix', 'Java']