当前位置:网站首页>The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)
The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)
2022-08-09 13:47:00 【A pig to】
剑指 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;
}
};
边栏推荐
- leetcode 20. Valid Parentheses 有效的括号(中等)
- Redis源码剖析之robj(redisObject)
- 用plot_hist_numeric()实现画直方图
- Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
- ftplib+ tqdm 上传下载进度条
- novel research
- ViewPager fragments of nested data blank page abnormal problem analysis
- MySQL备份与恢复 (转载非原创)
- 5G China unicom AP:B SMS ASCII 转码要求
- 【FPGA教程案例48】图像案例8——基于FPGA的RGB图像转化为HSV图像的实现,通过MATLAB进行辅助验证
猜你喜欢
随机推荐
2.微服务'黑话'集锦及Eureka注册中心相关概念
telnet+ftp to control and upgrade the device
Redis源码剖析之字典(dict)
5G China unicom repeater network management protocol real-time requirements
单面线路板与精密多层PCB线路板区别有哪些?
FFmpeg multimedia file processing (FFMPEG logging system)
二维数组&指针
基于 R 语言的深度学习——简单回归案例
ViewPager fragments of nested data blank page abnormal problem analysis
Flutter Getting Started and Advanced Tour (1) - Getting to Know Flutter
5G China unicom 一般性异常处理
SQL Server查询优化 (转载非原创)
kustomize入门示例及基本语法使用说明
glibc 内存管理模型 释放 C库内存缓存
电脑重装系统后桌面图标如何调小尺寸
Flutter Getting Started and Advanced Tour (8) Button Widget
ctfshow七夕杯2022
如何求最大公约数?
Extract EventBus encapsulation to base class using annotations
[极客大挑战 2019]Upload