标签:return problem solution 算法 lse can scom turn code
这道题可以用贪心算法的思想解决,类似于Jump Game II。
class Solution:
def canJump(self, nums: List[int]) -> bool:
curEnd = 0
curFarthest = 0
for i in range(len(nums)-1):
curFarthest = max(curFarthest, i + nums[i])
if i == curEnd:
curEnd = curFarthest
if curEnd >= len(nums) - 1:
break
if curEnd >= len(nums) - 1:
return True
else:
return False
标签:return problem solution 算法 lse can scom turn code
原文地址:https://www.cnblogs.com/RatsCommander/p/13809712.html