首页 > 其他 > 详细

leetcode 每日一题 55. 跳跃游戏

时间:2020-06-04 13:15:31      阅读:29      评论:0      收藏:0      [点我收藏+]

技术分享图片

贪心算法

思路:

参考45. 跳跃游戏 II

代码:

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

 

 

leetcode 每日一题 55. 跳跃游戏

原文:https://www.cnblogs.com/nilhxzcode/p/13042400.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!