跳跃游戏2

https://www.bilibili.com/video/BV1wb4y1b7df?spm_id_from=333.999.0.0

class Solution:
    def jump(self, nums: List[int]) -> int:
        n=len(nums)
        @cache
        def dp(i:int)->int :
            if i>=n-1:return 0
            if i+nums[i]>=n-1:return 1
            ans=n
            for s in range(1,nums[i]+1):
                ans=min(ans,dp(i+s)+1)
              
            return ans
        return dp(0)

你可能感兴趣的:(测试,django,python,开发语言)