当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
Flutter Getting Started and Advanced Tour (3) Text Widgets
5G Unicom Network Management Design Ideas
5G China unicom repeater network management protocol real-time requirements
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
[MRCTF2020]套娃-1
uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)
GIN初探,环境安装
5G China unicom 直放站 网管协议 实时性要求
第六届“强网杯”全国网络安全挑战赛
面试题精选:神奇的斐波那契数列
随机推荐
十六进制字符→十进制数字
5G China unicom AP:B SMS ASCII 转码要求
流量焦虑背后是企业对客户关系管理的不足
CPU-MIPS32指令架构(无内锁流水线微处理器)
ftplib+ tqdm upload and download progress bar
5G 联通网管设计思路
基于 R 语言的深度学习——简单回归案例
剑指offer,剪绳子2
Jenkins API groovy调用实践: Jenkins Core Api & Job DSL创建项目
ARM板卡增加路由功能
Standing wave ratio calculation method
Rust from entry to proficient 04 - data types
CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
NFS pays special attention to the problem of permissions
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
ftplib+ tqdm 上传下载进度条
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 16 Assignment
透明tune proxy
记录本项目中用到的系统调用与C库函数-2