0

I'm doing leetcode 70 in python in my IDE. However it came up with error.

class Solution:
    def climbStairs(self, n: int) -> int:
        cache = [None] * (n + 1)
        return self._helper(n, cache)

    def _helper(self, n, cache):
        if n < 0:
            return 0
        if n == 1 or n == 0:
            return 1
        if cache[n]:
            return cache[n]
        cache[n] = self._helper(n - 1, cache) + self._helper(n - 2, cache)
        return cache[n]

step = Solution.climbStairs(13)

print(step)

The error is :

`Traceback (most recent call last): File "/home/viktor/PycharmProjects/70. Climbing Stairs/70. Climbing Stairs.py", line 42, in step = Solution.climbStairs(13) TypeError: climbStairs() missing 1 required positional argument: 'n'

How can I deal with this?
Thanks

1 Answers1

0

You need to create an instance of Solution and call the method on that.

s = Solution()
step = s.climbStairs(13)

Otherwise there's no self object.

Barmar
  • 741,623
  • 53
  • 500
  • 612