知识点总结
- 针对二分查找的代码:
`auto bound = lower_bound(sums.begin(), sums.end(), target);
if (bound != sums.end()) {
ans = min(ans, static_cast<int>((bound - sums.begin()) - (i - 1)));
}
vector.end()是指向 容器最后一个元素+1.
2.滑动窗口;多使用格式: start++在内循环和外循环都可,下为在内循环的结构
while (end < n) {
sum += nums[end];
while (sum >= target) {
start++;
}
end++;
}