```
int helper(vector<int>&nums,int left, int right, int target){
if (left > right) return left;
int mid = (left+right)/2;
if(nums[mid]==target) return mid;
else if (nums[mid]<target) return helper(nums, mid+1,right,target);
else return helper(nums, left, mid-1, target);
}
int searchInsert(vector<int>& nums, int target) {
if (target > nums.back()) return nums.size();
return helper(nums, 0, nums.size(), target);
}
```