当前位置:网站首页>剑指 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;
}
};
边栏推荐
- Flutter入门进阶之旅(八)Button Widget
- JVM之配置介绍(一)
- telnet+ftp 对设备进行 操控 和 升级
- Standing wave ratio calculation method
- Flutter入门进阶之旅(一)-初识Flutter
- Unicom network management protocol block diagram
- 5G China unicom repeater network management protocol real-time requirements
- About the handling of variable parameters in the Retrofit network request URL
- 流量焦虑背后是企业对客户关系管理的不足
- Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
猜你喜欢
随机推荐
Flutter Getting Started and Advanced Tour (1) - Getting to Know Flutter
5G Unicom Network Management Design Ideas
read stream 特别注意
Flutter入门进阶之旅(八)Button Widget
如何求最大公约数?
AI basketball referee, walking is special, ask harden care don't care
Say goodbye to the AI era of hand looms
Flutter introduction advanced trip (5) Image Widget
中断系统结构及中断控制详解
The FPGA - work summary recently
自定义VIEW实现应用内消息提醒上下轮播
【HCIP持续更新】IS-IS协议原理与配置
5G China unicom 直放站 网管协议 实时性要求
Flutter Getting Started and Advanced Tour (8) Button Widget
FPGA中串口通信的时钟频率和波特率计数
造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
陈强教授《机器学习及R应用》课程 第十七章作业
在“Extend the Omniverse”比赛中构建用于 3D 世界的工具
WSA toolkit installed app store tip doesn't work how to solve?
绘制混合密度函数图以及添加分位数线









