0%

等差数列

利用等差数列求连续正数

力扣Offer57-II题

解题思路

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
List<int[]> result = new ArrayList<>();
int i = 1;
while(target>0)
{
target -= i++;
if(target>0 && target%i == 0)
{
int[] array = new int[i];
for(int k = target/i, j = 0; k < target/i+i; k++,j++)
{
array[j] = k;
}
result.add(array);
}
}
Collections.reverse(result);
return result.toArray(new int[0][]);