Solution In Java


  • 0
    D

    class Solution {
    public static void main(String[] args)
    {
    int nums[] = {-98,-55,0,15,88,89,987};
    int target = -500;
    int leftIdx = searchInsert(nums, target);
    System.out.println(leftIdx);
    }
    public static int searchInsert(int[] nums, int target) {

    	int low = 0;
    	int high = nums.length;
    	
    	while (low < high)
    	{
    		int mid = (low + high)/2;
    		if (nums[mid] > target || (true && target == nums[mid])){
    			high = mid;
    		}
    		else
    			low = mid + 1;
    	}
    	return low; 
    }
    

    }


Log in to reply
 

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