diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index e13079de..2668f222 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -2272,25 +2272,25 @@ public ArrayList FindNumbersWithSum(int[] array, int sum) { ```java public ArrayList> FindContinuousSequence(int sum) { ArrayList> ret = new ArrayList<>(); - int start = 1, end = 2; + int first = 1, last = 2; int curSum = 3; - while (start <= sum / 2 && end < sum) { + while (first <= sum / 2 && last < sum) { if (curSum > sum) { - curSum -= start; - start++; + curSum -= first; + first++; } else if (curSum < sum) { - end++; - curSum += end; + last++; + curSum += last; } else { ArrayList list = new ArrayList<>(); - for (int i = start; i <= end; i++) { + for (int i = first; i <= last; i++) { list.add(i); } ret.add(list); - curSum -= start; - start++; - end++; - curSum += end; + curSum -= first; + first++; + last++; + curSum += last; } } return ret; @@ -2447,7 +2447,7 @@ public double countProbability(int n, int s) { flag = 1 - flag; } int totalNum = (int) Math.pow(6, n); - return (double) dp[n - 1][s - 1] / totalNum; + return (double) dp[flag][s - 1] / totalNum; } ```