标签:search tar insert div cto 二分 tor amp target
1 class Solution 2 { 3 public: 4 int searchInsert(vector<int>& nums, int target) 5 { 6 int n = nums.size(); 7 int l = 0; 8 int r = n - 1; 9 if(target > nums[n - 1]) return n;//如果比最后一个元素都还大,则返回n 10 //二分模板,找到某个数大于等于target 11 while(l < r) 12 { 13 int mid = l + r >> 1; 14 if(nums[mid] >= target) r = mid; 15 else l = mid + 1; 16 } 17 return l; 18 } 19 };
标签:search tar insert div cto 二分 tor amp target
原文地址:https://www.cnblogs.com/yuhong1103/p/12512586.html