题解 | #和为S的连续正数序列#
和为S的连续正数序列
http://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe
暴力
import java.util.ArrayList;
public class Solution {
public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
ArrayList<ArrayList<Integer> > we = new ArrayList<>();
ArrayList<Integer> you = new ArrayList<>();
int uu=0;
for(int i = 1;i<sum;i++){
for(int j=i;j<sum;j++){
uu+=j;
you.add(j);
if(uu==sum){
we.add((ArrayList<Integer>) you.clone());
break;
}
if(uu>sum){
break;
}
}
you.clear();
uu=0;
}
return we;
}
}