Reserve an integer runtime error

  • 0

    Hi, All:
    I have the following code, but why it complains that 1 argument needed, I have given 2?
    Runtime error line 22.
    I don't even have 22 lines for this code.
    Please advise.

    class Solution:
    # @return an integer
    def reverse(myNum):
    y = str(myNum)
    newStr = ''

        for digit in y:
            if digit == '-':
        return newStr

  • 0

    What language is this?

    I expect the problem is that you put "y=y[:-1]" inside "for digit in y".

  • 0

    You must not modify the list of function arguments. In python, you need to pass 'self' as the first argument. i.e., reverse must take two arguments: self and myNum, in order to be properly called.

    BTW, line 22 is not part of your code; it is in the testing code that comes after your code.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.