public ArrayList<ArrayList<Integer> > FindContinuousSequence(int target) {
ArrayList<ArrayList<Integer> > ans = new ArrayList<>();
int l = 1;
int h = l+1;
while(h < target)
{
while(sum(l,h) < target)
{
h++;
}
while(h < target&&sum(l,h) >= target)
{
//System.out.println(sum(l,h));
if(sum(l,h) == target)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i = l ; i <= h ; i++)
{
list.add(i);
}
ans.add(list);
h++;
break;
}
l++;
}
}
return ans;
}
public static int sum(int i , int j )
{
int ans = 0;
while(i <= j)
{
ans += i;
i++;
}
return ans;
}
07-05
901
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-17
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交