标签:sea strong return tar ret 插入 inf span arch
题目:
解答:
1 class Solution { 2 public: 3 int searchInsert(vector<int> &nums, int target) 4 { 5 int left = 0; 6 int right = nums.size() - 1; 7 8 while(left <= right) 9 { 10 int mid =left + (right - left) / 2; 11 12 if(nums[mid] == target) 13 { 14 return mid; 15 } 16 else if(nums[mid] < target) 17 { 18 left = mid + 1; 19 } 20 else 21 { 22 right = mid - 1; 23 } 24 } 25 return left; 26 } 27 };
标签:sea strong return tar ret 插入 inf span arch
原文地址:https://www.cnblogs.com/ocpc/p/12830129.html