solution.cpp 326 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	int searchInsert(vector<int> &nums, int target)
	{
		int lo = -1;
		int hi = nums.size();
		while (lo + 1 < hi)
		{
			int mid = lo + (hi - lo) / 2;
			if (target > nums[mid])
			{
				lo = mid;
			}
			else
			{
				hi = mid;
			}
		}
		return hi;
	}
};