MY Comprehensible Solution,5ms


  • 0
    W
    public static int searchInsert(int[] nums, int target) {
    	    int lo=0,hi=nums.length-1,mid;
    	     while(lo<=hi){
    	        mid=lo+(hi-lo)/2;
    	        if(target>nums[mid]) lo=mid+1;
    	        else if(target<nums[mid]) hi=mid-1;
    	        else return mid;
    	        }
    	    return lo;
    	 }
    

Log in to reply
 

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