当前位置:网站首页>剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)
剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)
2022-08-09 12:45:00 【养猪去】
剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)
class Solution {
public:
vector<vector<int>> findContinuousSequence(int target) {
vector<vector<int>>vec;
vector<int> res;
for (int l = 1, r = 2; l < r;){
int sum = (l + r) * (r - l + 1) / 2;
if (sum == target) {
res.clear();
for (int i = l; i <= r; ++i) {
res.emplace_back(i);
}
vec.emplace_back(res);
l++;
} else if (sum < target) {
r++;
} else {
l++;
}
}
return vec;
}
};
边栏推荐
猜你喜欢
随机推荐
Redis源码剖析之数据过期(expire)
Flutter入门进阶之旅(二)Hello Flutter
我的2020年终总结
MySQL5.6到8.0的账号迁移
glibc memory management model freeing C library memory cache
K个结点的组内逆序调整
JVM常用监控工具解释以及使用
使用RecyclerView实现三级折叠列表
Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
陈强教授《机器学习及R应用》课程 第十五章作业
jenkins api create custom pipeline
[HCIP Continuous Update] Principle and Configuration of IS-IS Protocol
GIN初探,环境安装
数据挖掘-05
LnReader编译
第六届“强网杯”全国网络安全挑战赛
About the handling of variable parameters in the Retrofit network request URL
leetcode 20. Valid Parentheses 有效的括号(中等)
一维数组&指针
位图与位运算