ko
import java.util.ArrayList;
public class Solution {
public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
ArrayList<ArrayList<Integer>> res = new ArrayList<>();
int start=1,end=2,curSum=3;
while(end <= sum/2+1){
if(curSum<sum){
end++;
curSum+=end;
}else if(curSum>sum){
curSum-=start;
start++;
}else{
ArrayList<Integer> tmp = new ArrayList<>();
for(int i=start;i<=end;i++) tmp.add(i);
res.add(tmp);
curSum -= start;
start++;
end++;
curSum+=end;
}
}
return res;
}
} 

阿里云工作强度 603人发布