leetcode 每日一题 55. 跳跃游戏
贪心算法
思路:
代码:
class Solution: def canJump(self, nums: List[int]) -> bool: n,maxindex = len(nums),0 for i in range(n): if i <= maxindex: maxindex = max(maxindex,i+nums[i]) if maxindex >= n-1: return True return False
贪心算法
思路:
代码:
class Solution: def canJump(self, nums: List[int]) -> bool: n,maxindex = len(nums),0 for i in range(n): if i <= maxindex: maxindex = max(maxindex,i+nums[i]) if maxindex >= n-1: return True return False