Solution in Python


  • 0
    I
    class Solution(object):
        def is_overflow(self,x):
            if abs(x) > 2**31:
                return True
            
        def reverse(self, x):
            if x > 0:
                rev = int(str(x)[::-1])
                if self.is_overflow(rev):
                    return 0
                else:
                    return rev
            else:
                rev = -int(str(abs(x))[::-1])
                if self.is_overflow(rev):
                    return 0
                else:
                    return rev
    
    

    I write a function to judge whether the reversed integer overflows.
    Also, it is available in python3!


Log in to reply
 

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