1 class Solution(object): 2 def jump(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 """ 7 ln = len(nums) 8 curr = 0 9 last = 0 10 step = 0 11 for i in range(ln): 12 if i > last: 13 last = curr 14 step += 1 15 curr = max(curr, nums[i] +i) 16 return step
更新一道进入top 100中的hard难度的题目,这道题我在去年秋招的时候遇到过,当时没有做出来。
参考:https://leetcode.com/problems/jump-game-ii/discuss/562493/Java-and-Python-Greedy-DP