mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-31 19:13:42 +00:00
Update 57.2 和为 S 的连续正数序列.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+13
-12
@@ -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()][]);
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user