思路:
连续序列的最大数big,最小数small;区间之和为Sum
import java.util.ArrayList; public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum){ ArrayList<ArrayList<Integer>> res=new ArrayList<>(); int small=1; int big=2; if(sum<3){ return res; } while(small<big){//small !=(sum+1)/2 int s=SumOf(small,big); if(sum==s){ ArrayList<Integer> list=new ArrayList<>(); for(int i=small;i<=big;i++){ list.add(i); } res.add(list);// res.add(new ArrayList<>(list)); list.clear(); big++; } else if(s>sum){ small++; } else{ big++; } } return res; } public int SumOf(int small,int big){ int sum=0; for(int i=small;i<=big;i++){ sum=sum+i; } return sum; }