My concise O(m+n) Java solution
We start search the matrix from top right corner, initialize the current position to top right corner, if the target is greater than the value in current positi
We start search the matrix from top right corner, initialize the current position to top right corner, if the target is greater than the value in current position, then the target can not be in entire row of current position because the row is sorted, if the target is less than the value in current position, then the target can not in the entire column because the column is sorted too. We can rule out one row or one column each time, so the time complexity is O(m+n).\n\n    public class Solution {\n        public boolean searchMatrix(int[][] matrix, int target) {\n            if(matrix == null || matrix.length < 1 || matrix[0].length <1) {\n                return false;\n            }\n            int col = matrix[0].length-1;\n            int row = 0;\n            while(col >= 0 && row <= matrix.length-1) {\n                if(target == matrix[row][col]) {\n                    return true;\n                } else if(target < matrix[row][col]) {\n                    col--;\n                } else if(target > matrix[row][col]) {\n                    row++;\n                }\n            }\n            return false;\n        }\n    }
['Java']