```
class Solution(object):
def searchInsert(self, nums, target):
left = 0
right = len(nums)-1
while left < right:
mid = (right+left) // 2
if target > nums[mid]:
left = mid+1
elif target < nums[mid]:
right = mid-1
else:
return mid
if target > nums[left]:
return left + 1
else:
return left
```