Python tested code in IDLE but not accepted by Leetcode "AttributeError: Solution instance has no attribute 'reverse'"


  • 0
    K

    Assuming overflow is not considered but the code was tested in python IDLE and it was working but not here giving the attribute error of using reverse.
    class Solution:
    def intrev(integer):
    if '-' in str(integer):
    integer = str(integer).split('-')
    newinteger = list(integer[1])
    newinteger.reverse()
    x = ''
    for i in range(len(newinteger)):
    x = x + (newinteger[i])
    newinteger = str(x)
    return int('-'+newinteger)
    elif len(str(integer)) == 1:
    return integer
    else:
    integer = list(str(integer))
    integer.reverse()
    x = ''
    for i in range(len(integer)):
    x = x + (integer[i])
    integer = str(x)
    return int(integer)


Log in to reply
 

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