-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path41.java
28 lines (27 loc) · 802 Bytes
/
41.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.ArrayList;
public class Solution {
public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
//维护两个指针
ArrayList<ArrayList<Integer>> result=new ArrayList<ArrayList<Integer>>();
if(sum<=1) return result;
int low=1,high=2;
while(low<high)
{
int curSum=(high-low+1)*(high+low)/2;
if(curSum>sum)
low++;
else if(curSum<sum)
high++;
else
{
ArrayList<Integer> tmp=new ArrayList<Integer>();
for(int i=low;i<=high;i++)
tmp.add(i);
result.add(tmp);
low++;
high++;
}
}
return result;
}
}