滑动窗口写法
只能向右走,注意sum加减的顺序
class Solution {
public int[][] findContinuousSequence(int target) {
List<int[]> res = new ArrayList<>();
int i=1, j=2, sum=3;
while(i<j){
if(sum < target){
j++;
sum += j;
}else if(sum > target){
sum -= i;
i++;
}else {
int[] cun = new int[j-i+1];
for(int k=i; k<=j; k++)
cun[k-i] = k;
res.add(cun);
sum -= i;
i++;
}
}
return res.toArray(new int[0][]);
}
}