标签:col port seq span return sse code ret sequence
import java.util.*; public class Solution { public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) { if(sum < 0){ return null; } ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>(); for(int i = 1; i <= sum/2; i++){ ArrayList<Integer> subList = new ArrayList<Integer>(); int res = 0; for(int j = i; j < sum && res<sum ;j++ ){ res = res + j; if(res<sum){ subList.add(j); } if(res == sum){ subList.add(j); list.add(subList); } } } return list; } }
输出所有和为S的连续正数序列。序列内按照从小至大的顺序,序列间按照开始数字从小到大的顺序
标签:col port seq span return sse code ret sequence
原文地址:https://www.cnblogs.com/q-1993/p/10911540.html