Reverse Integer solution in Python by Hanan


  • 0
    S

    class Solution(object):
    def reverse(self, x):
    """
    The idea is to convert to string and reverse it
    :type x: int
    :rtype: int
    """
    if(x>=0):
    ans=str(x)[::-1]
    if (int(ans)<2147483647):
    return int(ans)

        if(x<0):
            ans=str(x)[::-1]
            if (int(ans[:-1]) < 2147483647):
                ans=int("-"+ ans[:-1])
                return ans
        
        return 0

Log in to reply
 

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