From e035548e40b9e056e18c87281e2b1ee1279213c1 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:07 +0800 Subject: [PATCH] =?UTF-8?q?Update=2057.2=20=E5=92=8C=E4=B8=BA=20S=20?= =?UTF-8?q?=E7=9A=84=E8=BF=9E=E7=BB=AD=E6=AD=A3=E6=95=B0=E5=BA=8F=E5=88=97?= =?UTF-8?q?.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/57.2 和为 S 的连续正数序列.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/notes/57.2 和为 S 的连续正数序列.md b/notes/57.2 和为 S 的连续正数序列.md index f09420f2..5ab87287 100644 --- a/notes/57.2 和为 S 的连续正数序列.md +++ b/notes/57.2 和为 S 的连续正数序列.md @@ -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> FindContinuousSequence(int sum) { - ArrayList> ret = new ArrayList<>(); +public int[][] fileCombination(int target) { + List 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 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()][]); } ```