public class Solution {
    public int searchInsert(int[] nums, int target) {
        if(nums == null || nums.length < 1 || target < nums[0]) return 0;
        if(target > nums[nums.length - 1])  return nums.length;
        
        int left = 0, right = nums.length;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if      (nums[mid] < target)    left = mid + 1;
            else if (nums[mid] > target)    right = mid;
            else    return mid;
        }
        return left;
    }
}

@@ -528,8 +528,590 @@
     %7D%0A%7D%0A
+%0A// solution 2 (faster)%0Apublic class Solution %7B%0A    public int searchInsert(int%5B%5D nums, int target) %7B%0A        if(nums.length %3C 1 %7C%7C target %3C nums%5B0%5D) return 0;%0A        if(target %3E nums%5Bnums.length - 1%5D)  return nums.length;%0A        %0A        int left = 0, right = nums.length, mid = 0;%0A        while(left %3C= right) %7B%0A            mid = left + (right - left) / 2;%0A            if      (nums%5Bmid%5D %3C target)    left = mid + 1;%0A            else if (nums%5Bmid%5D %3E target)    right = mid - 1;%0A            else    return mid;%0A        %7D%0A        return target %3E nums%5Bmid%5D ? mid + 1: mid;%0A    %7D%0A%7D%0A

Update 035.java