Solution in Python


  • 0
    M

    '''
    class Solution:
    def reverse(self, x):
    """
    :type x: int
    :rtype: int
    """
    if x == int('0'):
    return 0
    x = str(x)
    sign = str()
    if int(x).bit_length() <= 32:
    if '-' in x:
    sign = (x.partition('-')[1])
    y = x.strip('-')
    y = y.strip('0')
    rev = y[::-1]
    if int(rev).bit_length() < 32:
    if sign == '-':
    return int(sign+rev)
    else:
    return int(rev)
    else:
    return 0
    else:
    return 0
    '''


Log in to reply
 

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