Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
336 B
2
Indexable
class Solution {
public:
    int searchInsert(vector<int>& nums, int t) {
        int s=0,e=nums.size()-1;
        int mid=0;
        while(s<=e){
            mid =s+(e-s)/2;
            if(nums[mid]<t) s=mid+1;
            else if(nums[mid]>t) e=mid-1;
            else if(nums[mid]==t) return mid;
        }
        return s;
    }
};