Sword refers to the offer: and the continuous positive sequence of S is

小明 very fond of mathematics, one day he was doing mathematics homework, asked to calculate the sum of 9~16, he immediately wrote the correct answer is 100. But he is not satisfied with this, he is thinking about how many consecutive positive sequence sums are 100 (including at least two numbers). Not long after, he got another set of consecutive positive sums of 100: 18, 19, 20, 21, 22. Now give the question to you, can you quickly find out all the consecutive positive sequence for S? Good Luck!

左神的思维, double pointer problem, when the sum is less than sum, the big pointer continues +, otherwise small pointer +

public class Solution {
    public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
        ArrayList<ArrayList<Integer>> allRes = new ArrayList<ArrayList<Integer>>();
        int high = 2,low = 1; 
        while(high > low){
            int cur_sum = (high + low) * (high - low + 1) / 2;
            if(cur_sum < sum)  high++;     
            else if(cur_sum > sum)  low++; 
            else {
                ArrayList<Integer> res = new ArrayList<Integer>();
                for(int i = low; i <= high; i++)
                   res.add(i);
                allRes.add(res);
                low++;
            }                                      
        }
        return allRes;
    }
}