当前位置:网站首页>剑指 Offer 57 - II. 和为s的连续正数序列
剑指 Offer 57 - II. 和为s的连续正数序列
2022-07-16 18:25:00 【anieoo】
原题链接:剑指 Offer 57 - II. 和为s的连续正数序列
solution:
双指针维护一个窗口区间
class Solution {
public:
vector<vector<int>> findContinuousSequence(int target) {
vector<vector<int>> res;
int sum = 0; //维护窗口内的数字和
for(int l = 1,r = 1;r < target;r++) {
sum += r;
while(sum > target) {
sum -= l;
l++;
}
if(sum == target) { //保存满足target的正数序列
vector<int> path;
for(int i = l;i <= r;i++) {
path.push_back(i);
}
res.push_back(path);
}
}
return res;
}
};边栏推荐
- 【js 封装一个简单的异步API,获取异步操作结果和过程解析】
- 嵌入式开发:加速固件开发的7个技巧
- 知识图谱de构建与应用(四):知识获取
- 数据统计分析案例(对比分析、销量定比分析、同比、双坐标图、环比、shift、贡献度分析(帕累托法则)、差异化分析、resample、季节性波动分析)
- 这个加热器的热特性
- Multipartfile to Base64
- 数学方法 - 封装范围内随机整数-六位随机验证码-随机颜色字符串-进制转换 和 保留小数位
- Daily question · sword finger offer | 041 Average value of sliding window (same as 346) · queue
- Feign call delivery request header
- Equity structure design of founders and partners
猜你喜欢

数据统计分析案例(对比分析、销量定比分析、同比、双坐标图、环比、shift、贡献度分析(帕累托法则)、差异化分析、resample、季节性波动分析)

21. How does the program execute after entering the URL in the browser?

小程序页面导航

SkyWalking 针对 gRPC 的负载均衡和自动扩容实践

待处理问题
![[Xuelang download tutorial] 04 Xuelang download settings registry to prevent Chinese garbled code](/img/6f/d6693d347e9c50802218d4d40f8f2c.png)
[Xuelang download tutorial] 04 Xuelang download settings registry to prevent Chinese garbled code

市场监管总局:小布丁雪糕等15批次雪糕产品不合格

Redis cluster

数学建模不会 LaTex 排版 | 教你如何在 Word 中优雅地使用漂亮的 LaTex 公式

激活navicat提示rsa public key not find的问题
随机推荐
Use of seven cattle cloud
Tableau JDBC连接GraphDB
输入一个url全过程详解
prettier代码格式化工具的使用
Error: cannot read properties of undefined (reading 'foreach')
Construction and application of knowledge atlas de (IV): knowledge acquisition
记住这几点就能快速的去找到bug
创业公司股权结构设计(案例)
机器学习|BP(Back Propagation)神经网络
[untitled]
TransE模型学习笔记
SkyWalking 针对 gRPC 的负载均衡和自动扩容实践
[Xuelang download tutorial] 01 configuration of fiddler for Xuelang Download
[learning wave download tutorial] 02 learning wave download Fiddler learning wave plug-in configuration
你猜不到的代码
Equity structure design of start-up companies (cases)
Research on driverless dynamic obstacle avoidance strategy | robot dynamic obstacle avoidance strategy
数据统计分析案例(对比分析、销量定比分析、同比、双坐标图、环比、shift、贡献度分析(帕累托法则)、差异化分析、resample、季节性波动分析)
Applet page navigation
js 加快播放视频速度