7 Lines java solution

  • 0
    class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            if(matrix.length==0 || matrix[0].length==0) return false;
            int ad=matrix[0].length-1;
            for(int[] nums:matrix){
                while(nums[ad]>target && ad>0) ad--;
                if(nums[ad]==target) return true;
            return false;

Log in to reply

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