A JAVA SOLUTION


  • 0
    T

    This is my solution use JAVA.

    	public static int searchInsert( int[] nums, int target ){
    		int low = 0, high = nums.length - 1;
    		int middle = 0;
    		while( low <= high ){
    			middle = ( low + high ) / 2;
    			if( nums[middle] < target )
    				low = middle + 1;
    			else if( nums[middle] > target )
    				high = middle - 1;
    			else
    				break;
    		}
    		if( low > high ) return low;
    		else return middle;
    	}
    

Log in to reply
 

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