滑动窗口(Java版本)
和为S的连续正数序列
http://www.nowcoder.com/questionTerminal/c451a3fd84b64cb19485dad758a55ebe
public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) { ArrayList<ArrayList<Integer>> res = new ArrayList<>(); int left = 1,right = 1; int temp = 0; while(left <= sum/2){ if(temp < sum){ temp += right; right++; }else if(temp > sum){ temp -=left; left++; }else{ ArrayList<Integer> ans = new ArrayList<>(); for(int k = left;k<right;k++){ ans.add(k); } res.add(ans); temp -= left; left++; } } return res; }