Solution in Python


  • 0
    K

    Here's my solution in python....seems to work well

    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            
            isNeg = 1
            if x < 0: isNeg = -1
            x = abs(x)
            ctr = 0
            intLen = len(str(x))
            newInt = 0
            for i in range(intLen + 1):
                tempNum = x % 10
                x //= 10
                newInt += tempNum * 10 ** (intLen - i)
            return newInt // 10 * isNeg
    

Log in to reply
 

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