Update 57.2 和为 S 的连续正数序列.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:07 +08:00
parent edb277680b
commit e035548e40
+13 -12
View File
@@ -1,8 +1,8 @@
# 57.2 和为 S 的连续正数序列
## 题目描述
## 题目链接
[牛客网](https://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe?tpId=13&tqId=11194&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/)
## 题目描述
@@ -16,28 +16,29 @@
## 解题思路
```java
public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
public int[][] fileCombination(int target) {
List<int[]> ret = new ArrayList<>();
int start = 1, end = 2;
int curSum = 3;
while (end < sum) {
if (curSum > sum) {
while (end < target) {
if (curSum > target) {
curSum -= start;
start++;
} else if (curSum < sum) {
} else if (curSum < target) {
end++;
curSum += end;
} else {
ArrayList<Integer> list = new ArrayList<>();
for (int i = start; i <= end; i++)
list.add(i);
ret.add(list);
int[] arr = new int[end - start + 1];
for (int i = start; i <= end; i++) {
arr[i - start] = i;
}
ret.add(arr);
curSum -= start;
start++;
end++;
curSum += end;
}
}
return ret;
return ret.toArray(new int[ret.size()][]);
}
```