• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
鱼市口
博客园    首页    新随笔    联系   管理    订阅  订阅
Leetcode 55
class Solution:
    def canJump(self, nums: List[int]) -> bool:
        if len(nums) == 1:return True
        i = 0;j = i
        
        for i in range(100000):
            if j > i+nums[i]:pass
            else:j = i+nums[i]
            
            i+=1
            if i > j:break
            if j >= len(nums)-1:return True

        return False
                    

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.

Return true if you can reach the last index, or false otherwise.

nums.length <= 104

 

posted on 2023-08-28 01:47  鱼市口  阅读(6)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3