Skip to content

Commit 77a95b3

Browse files
committed
补充第 800 ~ 899 题的题目解析(增加 22 道题)
1 parent ef5bf06 commit 77a95b3

26 files changed

+2523
-3
lines changed

docs/00_preface/00_05_solutions_list.md

Lines changed: 23 additions & 1 deletion
Large diffs are not rendered by default.

docs/others/update_time.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## 2026-01
22

3+
- 2026-01-08 补充第 800 ~ 899 题的题目解析(增加 22 道题)
34
- 2026-01-07 补充第 800 ~ 899 题的题目解析(增加 37 道题)
4-
- 2026-01-05 补充第 700 ~ 799 题的题目解析(增加 8 道题)
5-
- 2026-01-04 补充第 700 ~ 799 题的题目解析(增加 9 道题)
5+
- 2026-01-06 补充第 700 ~ 799 题的题目解析(增加 8 道题)
6+
- 2026-01-05 补充第 700 ~ 799 题的题目解析(增加 9 道题)
67
- 2026-01-03 补充第 700 ~ 799 题的题目解析(增加 27 道题)
78
- 2026-01-02 补充第 600 ~ 699 题的题目解析(增加 34 道题)
89
- 2026-01-01 补充第 500 ~ 599 题的题目解析(增加 34 道题)

docs/solutions/0800-0899/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
- [0802. 找到最终的安全状态](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/find-eventual-safe-states.md)
66
- [0803. 打砖块](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/bricks-falling-when-hit.md)
77
- [0804. 唯一摩尔斯密码词](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/unique-morse-code-words.md)
8+
- [0805. 数组的均值分割](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/split-array-with-same-average.md)
89
- [0806. 写字符串需要的行数](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/number-of-lines-to-write-string.md)
910
- [0807. 保持城市天际线](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/max-increase-to-keep-city-skyline.md)
11+
- [0808. 分汤](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/soup-servings.md)
1012
- [0809. 情感丰富的文字](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/expressive-words.md)
1113
- [0810. 黑板异或游戏](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/chalkboard-xor-game.md)
1214
- [0811. 子域名访问计数](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/subdomain-visit-count.md)
@@ -16,6 +18,7 @@
1618
- [0815. 公交路线](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/bus-routes.md)
1719
- [0816. 模糊坐标](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/ambiguous-coordinates.md)
1820
- [0817. 链表组件](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/linked-list-components.md)
21+
- [0818. 赛车](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/race-car.md)
1922
- [0819. 最常见的单词](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/most-common-word.md)
2023
- [0820. 单词的压缩编码](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/short-encoding-of-words.md)
2124
- [0821. 字符的最短距离](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/shortest-distance-to-a-character.md)
@@ -34,47 +37,66 @@
3437
- [0834. 树中距离之和](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/sum-of-distances-in-tree.md)
3538
- [0835. 图像重叠](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/image-overlap.md)
3639
- [0836. 矩形重叠](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/rectangle-overlap.md)
40+
- [0837. 新 21 点](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/new-21-game.md)
41+
- [0838. 推多米诺](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/push-dominoes.md)
42+
- [0839. 相似字符串组](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/similar-string-groups.md)
3743
- [0840. 矩阵中的幻方](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/magic-squares-in-grid.md)
3844
- [0841. 钥匙和房间](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/keys-and-rooms.md)
45+
- [0842. 将数组拆分成斐波那契序列](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/split-array-into-fibonacci-sequence.md)
3946
- [0843. 猜猜这个单词](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/guess-the-word.md)
4047
- [0844. 比较含退格的字符串](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/backspace-string-compare.md)
4148
- [0845. 数组中的最长山脉](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/longest-mountain-in-array.md)
4249
- [0846. 一手顺子](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/hand-of-straights.md)
4350
- [0847. 访问所有节点的最短路径](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/shortest-path-visiting-all-nodes.md)
51+
- [0848. 字母移位](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/shifting-letters.md)
4452
- [0849. 到最近的人的最大距离](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/maximize-distance-to-closest-person.md)
4553
- [0850. 矩形面积 II](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/rectangle-area-ii.md)
4654
- [0851. 喧闹和富有](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/loud-and-rich.md)
4755
- [0852. 山脉数组的峰顶索引](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/peak-index-in-a-mountain-array.md)
4856
- [0853. 车队](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/car-fleet.md)
4957
- [0854. 相似度为 K 的字符串](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/k-similar-strings.md)
5058
- [0855. 考场就座](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/exam-room.md)
59+
- [0856. 括号的分数](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/score-of-parentheses.md)
60+
- [0857. 雇佣 K 名工人的最低成本](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/minimum-cost-to-hire-k-workers.md)
5161
- [0858. 镜面反射](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/mirror-reflection.md)
5262
- [0859. 亲密字符串](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/buddy-strings.md)
5363
- [0860. 柠檬水找零](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/lemonade-change.md)
5464
- [0861. 翻转矩阵后的得分](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/score-after-flipping-matrix.md)
5565
- [0862. 和至少为 K 的最短子数组](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/shortest-subarray-with-sum-at-least-k.md)
5666
- [0863. 二叉树中所有距离为 K 的结点](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/all-nodes-distance-k-in-binary-tree.md)
67+
- [0864. 获取所有钥匙的最短路径](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/shortest-path-to-get-all-keys.md)
68+
- [0865. 具有所有最深节点的最小子树](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/smallest-subtree-with-all-the-deepest-nodes.md)
69+
- [0866. 回文质数](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/prime-palindrome.md)
5770
- [0867. 转置矩阵](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/transpose-matrix.md)
5871
- [0868. 二进制间距](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/binary-gap.md)
72+
- [0869. 重新排序得到 2 的幂](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/reordered-power-of-2.md)
5973
- [0870. 优势洗牌](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/advantage-shuffle.md)
6074
- [0871. 最低加油次数](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/minimum-number-of-refueling-stops.md)
6175
- [0872. 叶子相似的树](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/leaf-similar-trees.md)
6276
- [0873. 最长的斐波那契子序列的长度](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/length-of-longest-fibonacci-subsequence.md)
77+
- [0874. 模拟行走机器人](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/walking-robot-simulation.md)
6378
- [0875. 爱吃香蕉的珂珂](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/koko-eating-bananas.md)
6479
- [0876. 链表的中间结点](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/middle-of-the-linked-list.md)
6580
- [0877. 石子游戏](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/stone-game.md)
81+
- [0878. 第 N 个神奇数字](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/nth-magical-number.md)
82+
- [0879. 盈利计划](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/profitable-schemes.md)
6683
- [0880. 索引处的解码字符串](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/decoded-string-at-index.md)
6784
- [0881. 救生艇](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/boats-to-save-people.md)
85+
- [0882. 细分图中的可到达节点](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/reachable-nodes-in-subdivided-graph.md)
86+
- [0883. 三维形体投影面积](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/projection-area-of-3d-shapes.md)
6887
- [0884. 两句话中的不常见单词](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/uncommon-words-from-two-sentences.md)
88+
- [0885. 螺旋矩阵 III](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/spiral-matrix-iii.md)
6989
- [0886. 可能的二分法](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/possible-bipartition.md)
7090
- [0887. 鸡蛋掉落](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/super-egg-drop.md)
7191
- [0888. 公平的糖果交换](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/fair-candy-swap.md)
7292
- [0889. 根据前序和后序遍历构造二叉树](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/construct-binary-tree-from-preorder-and-postorder-traversal.md)
7393
- [0890. 查找和替换模式](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/find-and-replace-pattern.md)
94+
- [0891. 子序列宽度之和](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/sum-of-subsequence-widths.md)
7495
- [0892. 三维形体的表面积](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/surface-area-of-3d-shapes.md)
7596
- [0893. 特殊等价字符串组](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/groups-of-special-equivalent-strings.md)
7697
- [0894. 所有可能的真二叉树](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/all-possible-full-binary-trees.md)
7798
- [0895. 最大频率栈](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/maximum-frequency-stack.md)
7899
- [0896. 单调数列](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/monotonic-array.md)
79100
- [0897. 递增顺序搜索树](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/increasing-order-search-tree.md)
80101
- [0898. 子数组按位或操作](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/bitwise-ors-of-subarrays.md)
102+
- [0899. 有序队列](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0800-0899/orderly-queue.md)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# [0857. 雇佣 K 名工人的最低成本](https://leetcode.cn/problems/minimum-cost-to-hire-k-workers/)
2+
3+
- 标签:贪心、数组、排序、堆(优先队列)
4+
- 难度:困难
5+
6+
## 题目链接
7+
8+
- [0857. 雇佣 K 名工人的最低成本 - 力扣](https://leetcode.cn/problems/minimum-cost-to-hire-k-workers/)
9+
10+
## 题目大意
11+
12+
**描述**
13+
14+
有 $n$ 名工人。 给定两个数组 $quality$ 和 $wage$ ,其中,$quality[i]$ 表示第 $i$ 名工人的工作质量,其最低期望工资为 $wage[i]$。
15+
16+
现在我们想雇佣 $k$ 名工人组成一个 工资组。在雇佣 一组 $k$ 名工人时,我们必须按照下述规则向他们支付工资:
17+
18+
1. 对工资组中的每名工人,应当按其工作质量与同组其他工人的工作质量的比例来支付工资。
19+
2. 工资组中的每名工人至少应当得到他们的最低期望工资。
20+
21+
给定整数 $k$。
22+
23+
**要求**
24+
25+
返回「组成满足上述条件的付费群体所需的最小金额」。与实际答案误差相差在 $10^{-5}$ 以内的答案将被接受。
26+
27+
**说明**
28+
29+
- $n == quality.length == wage.length$。
30+
- $1 \le k \le n \le 10^{4}$。
31+
- $1 \le quality[i], wage[i] \le 10^{4}$。
32+
33+
**示例**
34+
35+
- 示例 1:
36+
37+
```python
38+
输入: quality = [10,20,5], wage = [70,50,30], k = 2
39+
输出: 105.00000
40+
解释: 我们向 0 号工人支付 70,向 2 号工人支付 35
41+
```
42+
43+
- 示例 2:
44+
45+
```python
46+
输入: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3
47+
输出: 30.66667
48+
解释: 我们向 0 号工人支付 4,向 2 号和 3 号分别支付 13.33333
49+
```
50+
51+
## 解题思路
52+
53+
### 思路 1:贪心 + 堆
54+
55+
关键观察:如果我们选定了某个工人作为"基准",其工资恰好等于最低期望工资,那么其他工人的工资由他们的工作质量比例决定。
56+
57+
设基准工人的工资期望比为 $r = \frac{wage}{quality}$,那么所有工人的工资期望比都不能超过 $r$,否则无法满足最低工资要求。
58+
59+
算法步骤:
60+
61+
1. 计算每个工人的工资期望比 $ratio[i] = \frac{wage[i]}{quality[i]}$
62+
2. 按照 $ratio$ 从小到大排序
63+
3. 枚举每个工人作为工资期望比最大的工人(基准)
64+
4. 对于当前基准,选择前面 $k-1$ 个工作质量最小的工人,使用大顶堆维护
65+
5. 计算总成本:$ratio \times \sum quality$
66+
67+
### 思路 1:代码
68+
69+
```python
70+
class Solution:
71+
def mincostToHireWorkers(self, quality: List[int], wage: List[int], k: int) -> float:
72+
import heapq
73+
74+
n = len(quality)
75+
# 计算每个工人的工资期望比,并按比例排序
76+
workers = sorted([(wage[i] / quality[i], quality[i]) for i in range(n)])
77+
78+
min_cost = float('inf')
79+
quality_sum = 0 # 当前选中的工人的工作质量之和
80+
max_heap = [] # 大顶堆,存储工作质量(取负数实现大顶堆)
81+
82+
for ratio, q in workers:
83+
# 将当前工人加入堆
84+
heapq.heappush(max_heap, -q)
85+
quality_sum += q
86+
87+
# 如果堆中元素超过 k 个,移除工作质量最大的
88+
if len(max_heap) > k:
89+
quality_sum += heapq.heappop(max_heap) # 注意是负数,所以用加法
90+
91+
# 如果堆中恰好有 k 个工人,计算成本
92+
if len(max_heap) == k:
93+
min_cost = min(min_cost, ratio * quality_sum)
94+
95+
return min_cost
96+
```
97+
98+
### 思路 1:复杂度分析
99+
100+
- **时间复杂度**:$O(n \log n)$,其中 $n$ 是工人数量。排序需要 $O(n \log n)$,每个工人最多入堆出堆一次,堆操作需要 $O(n \log k)$。
101+
- **空间复杂度**:$O(n)$,需要存储排序后的工人信息和堆。
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# [0837. 新 21 点](https://leetcode.cn/problems/new-21-game/)
2+
3+
- 标签:数学、动态规划、滑动窗口、概率与统计
4+
- 难度:中等
5+
6+
## 题目链接
7+
8+
- [0837. 新 21 点 - 力扣](https://leetcode.cn/problems/new-21-game/)
9+
10+
## 题目大意
11+
12+
**描述**
13+
14+
爱丽丝参与一个大致基于纸牌游戏「21点」规则的游戏,描述如下:
15+
16+
爱丽丝以 0 分开始,并在她的得分少于 $k$ 分时抽取数字。 抽取时,她从 $[1, maxPts]$ 的范围中随机获得一个整数作为分数进行累计,其中 $maxPts$ 是一个整数。每次抽取都是独立的,其结果具有相同的概率。
17+
18+
当爱丽丝获得 $k$ 分或更多分时,她就停止抽取数字。
19+
20+
**要求**
21+
22+
计算爱丽丝的分数不超过 $n$ 的概率。
23+
24+
**说明**
25+
26+
- 与实际答案误差不超过 $10^{-5}$ 的答案将被视为正确答案。
27+
- $0 \le k \le n \le 10^{4}$。
28+
- $1 \le maxPts \le 10^{4}$。
29+
30+
**示例**
31+
32+
- 示例 1:
33+
34+
```python
35+
输入:n = 10, k = 1, maxPts = 10
36+
输出:1.00000
37+
解释:爱丽丝得到一张牌,然后停止。
38+
```
39+
40+
- 示例 2:
41+
42+
```python
43+
输入:n = 6, k = 1, maxPts = 10
44+
输出:0.60000
45+
解释:爱丽丝得到一张牌,然后停止。 在 10 种可能性中的 6 种情况下,她的得分不超过 6 分。
46+
```
47+
48+
## 解题思路
49+
50+
### 思路 1:动态规划 + 滑动窗口
51+
52+
定义 $dp[x]$ 表示从分数为 $x$ 的情况开始,最终得分不超过 $n$ 的概率。
53+
54+
状态转移:
55+
- 当 $x \ge k$ 时,游戏停止,如果 $x \le n$,则 $dp[x] = 1$,否则 $dp[x] = 0$
56+
- 当 $x < k$ 时,可以抽取 $[1, maxPts]$ 中的任意数字,每个数字的概率为 $\frac{1}{maxPts}$:
57+
$$dp[x] = \frac{1}{maxPts} \sum_{i=1}^{maxPts} dp[x+i]$$
58+
59+
为了优化计算,我们可以维护一个滑动窗口的和 $sum$,表示 $\sum_{i=x+1}^{x+maxPts} dp[i]$。
60+
61+
### 思路 1:代码
62+
63+
```python
64+
class Solution:
65+
def new21Game(self, n: int, k: int, maxPts: int) -> float:
66+
# 特判:如果 k = 0 或 n >= k + maxPts - 1,概率为 1
67+
if k == 0 or n >= k + maxPts - 1:
68+
return 1.0
69+
70+
# dp[x] 表示从分数 x 开始,最终得分不超过 n 的概率
71+
dp = [0.0] * (n + 1)
72+
dp[0] = 1.0
73+
74+
# sum 表示滑动窗口的和
75+
window_sum = 1.0
76+
77+
for x in range(1, n + 1):
78+
# 当前分数的概率
79+
dp[x] = window_sum / maxPts
80+
81+
if x < k:
82+
# 如果还可以继续抽牌,将当前概率加入窗口
83+
window_sum += dp[x]
84+
85+
# 移除窗口左边界
86+
if x >= maxPts:
87+
window_sum -= dp[x - maxPts]
88+
89+
# 答案是从 0 分开始,最终得分在 [k, n] 范围内的概率
90+
return dp[0] if k == 0 else sum(dp[k:n+1]) / maxPts * maxPts if k > 0 else dp[0]
91+
```
92+
93+
实际上,我们需要重新理解题意。让我重写:
94+
95+
```python
96+
class Solution:
97+
def new21Game(self, n: int, k: int, maxPts: int) -> float:
98+
# 特判
99+
if k == 0 or n >= k + maxPts - 1:
100+
return 1.0
101+
102+
# dp[x] 表示得分为 x 时,最终得分不超过 n 的概率
103+
dp = [0.0] * (k + maxPts)
104+
105+
# 初始化:得分在 [k, n] 范围内的概率为 1
106+
for i in range(k, min(n + 1, k + maxPts)):
107+
dp[i] = 1.0
108+
109+
# 滑动窗口和
110+
window_sum = min(n - k + 1, maxPts)
111+
112+
# 从 k-1 倒推到 0
113+
for x in range(k - 1, -1, -1):
114+
dp[x] = window_sum / maxPts
115+
# 更新窗口:加入 dp[x+1],移除 dp[x+maxPts+1]
116+
window_sum += dp[x]
117+
if x + maxPts < len(dp):
118+
window_sum -= dp[x + maxPts]
119+
120+
return dp[0]
121+
```
122+
123+
### 思路 1:复杂度分析
124+
125+
- **时间复杂度**:$O(k + maxPts)$,需要计算 $k + maxPts$ 个状态。
126+
- **空间复杂度**:$O(k + maxPts)$,需要存储 $dp$ 数组。

0 commit comments

Comments
 (0)