-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjump.py
More file actions
27 lines (23 loc) · 665 Bytes
/
Copy pathjump.py
File metadata and controls
27 lines (23 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# coding=utf-8
"""
@project : algorithmPython
@ide : PyCharm
@file : jump
@author : illusion
@desc : 45. 跳跃游戏 II https://leetcode-cn.com/problems/jump-game-ii/
@create : 2021/6/8 1:47 下午:11
"""
class Solution:
def jump(self, nums: [int]) -> int:
if not len(nums):
return 0
dp = [9999999] * len(nums)
dp[0] = 0
for i in range(len(nums)):
for j in range(i + 1, i + nums[i] + 1):
if j >= len(nums):
break
dp[j] = min(dp[j], dp[i] + 1)
return dp[-1]
if __name__ == '__main__':
print(Solution().jump([2, 3, 1, 1, 4]))