Java 0ms solution


  • 0
    S

    ...
    public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {

    	 if(matrix==null) return false;
    	 int row=matrix.length;
    	 int column=matrix[0].length;
    	 int start=0;
    	 int end=(row*column)-1;
    	 int k1,k2;
    	 while(start<=end){
    		 k1=((start+end)/2)/column;
    		 k2=((start+end)/2)%column;
    		 if(target==matrix[k1][k2]) return true;
    		 if(target>matrix[k1][k2]) start=((start+end)/2)+1;
    		 else{
    			 end=((start+end)/2)-1;
    		 }
    				 
    		 
    	 }
    	 
    	 return false;
    }
    

    }
    ...


Log in to reply
 

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