美文网首页
55. Jump Game

55. Jump Game

作者: poteman | 来源:发表于2019-07-24 17:53 被阅读0次
class Solution(object):
    # 思路:
    # 维护一个reach变量,代码能走到的最远index
    # while循环, i <= reach,
    # 每次更新reach
    def canJump(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        reach = 0
        i = 0
        while i <= reach:
            reach = max(reach, i+nums[i])
            if reach >= len(nums) - 1:
                return True
            i += 1
        return False

相关文章

网友评论

      本文标题:55. Jump Game

      本文链接:https://www.haomeiwen.com/subject/iksfrctx.html