Reverse Integer


2018-05-19 02:27:55 by sikoay with 0 comments 1 Hits
Blog 1

Reverse Integer


反转整数,这也太简单了吧。。。。


class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        numstr = str(abs(x))
        lennum = -len(numstr)
        i = -1
        result = ''
        while i >= lennum:
            result += numstr[i]
            i -= 1
        if x < 0:
            result = -int(result)
        else:
            result = int(result)
        if result > 2147483647 or result < -2147483648:
            return 0
        return result


Tags:

回复 (0)

Leave a Comment