搜索插入位置⚓︎ Leetcode题目链接 描述⚓︎ 详见中文题目链接。 解答⚓︎ 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int searchInsert(vector<int>& nums, int target) { int l = -1, r = nums.size(); while (l + 1 < r) { int mid = l + r >> 1; if (nums[mid] >= target) r = mid; else l = mid; } return r; } };