Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.
解法1:Binary Search O(NLogn)
因为是sorted, 用binary search很容易解决。要注意的是最后判断nums[start], nums[end]的时候如果都没有符合的,那么说明要插入的位置是array的尾巴,要返回的结果是end+1, 比如searchInsert([0],1)
这样的情况。
C++
Java