LowerBound

LowerBound

Lower Bound 是使用二分查找的办法求 大于等于 i 的第一个位置

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int lowerBound(vector<int>& nums, int i) {
int l = 0, r = nums.size();
while (l < r) {
int mid = (l + r) / 2;
if (nums[mid] >= i) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
};

时间复杂度

O(logn)

空间复杂度

O(1)

作者

shouyi.www

发布于

2020-04-25

更新于

2025-01-30

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×