```
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
return self.binary_search(nums, target)
def binary_search(self, nums, target):
i = 0
j = len(nums) - 1
while i <= j:
mid = (i + j) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
j -= 1
else:
i += 1
return i
```