站内站外找到的解答都是关于__init__()写错了的问题。可是我没用__init__()啊。求大神指教我错在哪里了???
这是leetcode上的45题,看的别人的答案,在leetcode上能运行出来,自己在jupyter book上就运行不出来了(加了最后2句)。
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)
in
13 return counter
14
---> 15 a = Solution([2,3,1,1,4])
16 print(a.jump())
TypeError: Solution() takes no arguments