Solution() takes no arguments何解?(非__init__()的问题)

这是leetcode上的45题,看的别人的答案,在leetcode上能运行出来,自己在jupyter book上就运行不出来了(加了最后2句)。
站内站外找到的解答都是关于__init__()写错了的问题。可是我没用__init__()啊。求大神指教我错在哪里了???

from typing import List

class Solution:
    def jump(self, nums: List[int]) -> int:
        counter = 0  # 移动次数
        curr_end = 0  # 当前跳跃的终点
        curr_farthest = 0  # 最远位置的下标
        for i in range(len(nums) - 1):
            curr_farthest = max(curr_farthest, i + nums[i])
            if i == curr_end:
                counter += 1
                curr_end = curr_farthest
        return counter
    
a = Solution([2,3,1,1,4])
print(a.jump())

报错信息如下:

TypeError                                 Traceback (most recent call last)
<ipython-input-7-6e1137fe93e9> in <module>
     13         return counter
     14 
---> 15 a = Solution([2,3,1,1,4])
     16 print(a.jump())

TypeError: Solution() takes no arguments
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值