【LeetCode】55. 跳跃游戏 python实现

在这里插入图片描述

解题思路

请参考【LeetCode】45. 跳跃游戏 II python实现

python 代码

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        start = 0
        end = 1
        n = len(nums)
        step = 0
        while end < n:
            temp = 0
            for i in range(start,end):
                temp = max(temp,i + nums[i])
            start = end
            end = temp + 1
            if start==end:
                return False
            step += 1
        return True

s = Solution()
result = s.canJump([3,2,1,0,4])
print(result)
发布了222 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_42247922/article/details/104611735
今日推荐