Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created July 28, 2019 17:31
Show Gist options
  • Save kanrourou/8999aa46355cb912408b19928ed23801 to your computer and use it in GitHub Desktop.
Save kanrourou/8999aa46355cb912408b19928ed23801 to your computer and use it in GitHub Desktop.
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int len = nums.size(), lo = 0, hi = len;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (nums[mid] < target)
lo = mid + 1;
else
hi = mid;
}
return lo;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment