当前位置:网站首页>Sword finger offer notes: t57 - ii Continuous positive sequence with sum s
Sword finger offer notes: t57 - ii Continuous positive sequence with sum s
2022-07-27 11:48:00 【Ignorant little nine】
T57 - II. And for s Continuous positive sequence of
Enter a positive integer target , Output all and as target A sequence of continuous positive integers ( Contains at least two numbers ).
The numbers in the sequence are arranged from small to large , The different sequences are arranged in descending order according to the first number .
Example 1:
Input :target = 9
Output :[[2,3,4],[4,5]]
Example 2:
Input :target = 15
Output :[[1,2,3,4,5],[4,5,6],[7,8]]
Limit :
1 <= target <= 10^5
solution 1
Didn't do it
solution 2
class Solution {
public int[][] findContinuousSequence(int target) {
int left = 1;
int right = 2;
List<int[]> res = new ArrayList<>();
while (left < right) {
int sum = (left + right) * (right - left + 1) / 2;
if (sum == target){
int[] arr = new int[right - left + 1];
for (int k = left; k <= right; k++) {
arr[k - left] = k;
}
res.add(arr);
left++;
}
else if (sum < target) {
right++;
}
else {
left++;
}
}
return res.toArray(new int[res.size()][]);
}
}
Execution time :4 ms, In all Java Defeated in submission **56.28%** Users of
Memory consumption :36.4 MB, In all Java Defeated in submission **86.99%** Users of
Time complexity :O(target)O(target). Sliding window moves at most target/2 Time
Spatial complexity :O(1)O(1). Exclude the necessary storage result array , Just save the left and right pointers
author : Painter Dapeng
link :https://leetcode-cn.com/leetbook/read/illustrate-lcof/5017gs/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- Solution of digital tube flash back after proteus8 professional version cracking
- Could not load dynamic library ‘libcudnn.so.8‘;
- Some commonly used shortcut keys for MathType
- 基于反馈率的控制系统原理
- 局域网SDN技术硬核内幕 11 云网融合CP的关键——层次化端口绑定
- The C programming language (2nd) -- Notes -- 1.6
- 一些MathType常用快捷键
- PWM的原理和PWM波的产生
- 开源flink有写holo的Datastream connector或者flink sql conn
- Difference quotient approximation of wechat quotient
猜你喜欢

TapNet: Multivariate Time Series Classification with Attentional Prototypical Network

Proteus8专业版破解后用数码管闪退的解决
![[machine learning whiteboard derivation series] learning notes --- conditional random fields](/img/cc/87d8822b659b31360546adf057ef00.png)
[machine learning whiteboard derivation series] learning notes --- conditional random fields
![[machine learning whiteboard derivation series] learning notes - support vector machine and principal component analysis](/img/54/dc232f737da99c7097c395a326e74f.png)
[machine learning whiteboard derivation series] learning notes - support vector machine and principal component analysis

Shell script text three swordsmen sed

【Unity入门计划】CreatorKitFPS:第一人称射击3D小游戏

Shell脚本文本三剑客之sed

SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series

Analysis of the use of JUC framework from runnable to callable to futuretask

Newton-Raphson迭代法
随机推荐
Sword finger offer note: T39. Numbers that appear more than half of the time in the array
Sword finger offer notes: T53 - ii Missing numbers from 0 to n-1
局域网SDN硬核技术内幕 25 展望未来——RDMA(下)
[untitled] multimodal model clip
你真的会写二分查找吗——变种二分查找
LNMP架构搭建(部署Discuz论坛)
Summary of leetcode SQL exercises (MySQL Implementation)
Error encountered in adding quick open option to right-click menu:
[machine learning whiteboard derivation series] learning notes - probability graph model and exponential family distribution
Source code compilation and installation lamp
LeetCode 03: T58. 最后一个单词的长度(简单); 剑指 Offer 05. 替换空格(简单); 剑指 Offer 58 - II. 左旋转字符串(简单)
Principle of PWM and generation of PWM wave
The C programming language 2nd -- Notes -- 6.7
N ¨UWA: Visual Synthesis Pre-training for Neural visUal World creAtionChenfei
Ask the big guys, is there transaction control for using flick sink data to MySQL? If at a checkpoint
剑指 Offer 笔记: T39. 数组中出现次数超过一半的数字
origin如何作一张图中多张子图是柱状图(或其他图)
Wilcoxon rank sum and signed rank
微机和单片机的区别
请教大佬们,请问用flink sink数据到mysql有事务控制吗?如果在一个checkpoint时