clean reversed 32 bit integer


  • 0
    I
    class Solution:
        def reverse(self, x):
            """ We create the reversed integer using the modulo operator :)
            :type x: int
            :rtype: int
            """
            r = 0
            i = abs( x )
            while i != 0:
                r = r * 10 + i % 10
                i = i // 10
    
            if x < 0:
                r = -r
            if  r < -2147483648 or 2147483647 < r:
                return 0
            return r
    
    

Log in to reply
 

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