-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution58-1.java
More file actions
29 lines (27 loc) · 895 Bytes
/
Solution58-1.java
File metadata and controls
29 lines (27 loc) · 895 Bytes
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
29
class Solution {
public int[][] findContinuousSequence(int target) {
int left = 1;
int right = 1;
int sum = 0;
List<int[]> res = new ArrayList<>();
while (left <= (target / 2)) {
if (sum < target) {
sum += right;
right++;
} else if (sum > target) {
sum -= left;
left++;
} else {
int[] array = new int[right - left];
for (int i = left; i < right; i++) {
array[i - left] = i;
}
res.add(array);
sum -= left;
left++;
}
}
return res.toArray(new int[res.size()][]);
}
}
// https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/solution/shi-yao-shi-hua-dong-chuang-kou-yi-ji-ru-he-yong-h/