看懂意思之后发现直接使用low_bound即可
class Solution { public: int searchInsert(vector<int>& nums, int target) { int left=0,right=nums.size(),mid; while(left<right){ mid=(left+right)/2; if(nums[mid]>=target) right=mid; else left=mid+1; } return left; } };
Last updated 5 years ago