Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 337cac6

Browse files
🧙‍♂️(greedy): 修该 45 题题解格式
1 parent cecabe6 commit 337cac6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

‎docs/algorithm/greedy/README.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,32 @@ dp[x] = min(dp[n1], dp[n2], ..., dp[nx]) + 1
1515
```
1616

1717
```python
18-
18+
class Solution(object):
19+
def jump(self, nums):
20+
"""
21+
:type nums: List[int]
22+
:rtype: int
23+
"""
24+
length = len(nums)
25+
dp = [0 for _ in range(length)]
26+
27+
for i in range(length):
28+
num = nums[i]
29+
for j in range(1, num + 1):
30+
if i + j < length:
31+
if dp[i + j] == 0:
32+
dp[i + j] = dp[i] + 1
33+
else:
34+
dp[i + j] = min(dp[i] + 1, dp[i + j])
35+
36+
return dp[length - 1]
1937
```
2038

2139
### 解法二:贪心
2240

2341
主要思想:每次都要跳到**能跳到更远位置**的点上。
2442

25-
```
43+
```python
2644
class Solution(object):
2745
def jump(self, nums):
2846
"""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /