0ms efficient Java solution


  • 0
    R
    public class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            int size = matrix[0].length;
            for(int i=0;i<matrix.length;i++){
                int[] row = matrix[i];
                if(row[size-1]>=target && row[0]<=target){
                    return Arrays.binarySearch(row, target)>=0;
                }
            }
            return false;
        }
    }
    

Log in to reply
 

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