I used a binary search, by 2 pointers, left and right. In every iteration, I through away half of the nums. So in the first loop I can find the first instance of the smallest larger number. then the rest is pretty straightforward ^8^ (first time writing a post~)

```
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
#first use binary search to find the closest larger number in the array
#also we found the first instance of the closest larger number in this way!
n = len(nums)
l , r = 0, n-1
while l<r:
m = int((l+r)/2)
if nums[m]<target: l=m+1
else: r = m
#whether we have found the number?
if nums[l] == target:
return l
#in this case, the target should be added in the end, out of range
if l == n-1 and nums[l]<target:
return l+1
return l
```