[TODO] Reverse Integer

Reverse Integer

Currently only works for postive numbers since // operation floors in negative case, changing the numbers.

class Solution:
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        if x == 0:
            return 0
        elif x < 10 and x > -10:
            return x
        
        stack = []
        negative = True if x < 0 else False
        
        if negative:
            stack += '-'
        
        while x >= 10 or x <= -10:
            stack += str(x % 10)
            x = x // 10
        if x != 0:
            stack += str(x % 10)
        
        # merge all together convert and return
        return int("".join(stack))