9. Palindrome Number Leetcode Python 2016 new Season

来源:互联网 发布:手机炒股软件ene 编辑:程序博客网 时间:2024/06/08 19:59

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Show Tags
Show Similar Problems





The problem requirement doesn't make sense, we still need constant space to do this problem. the time complexity is O(log(n)).
class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        tmp_x = x        residual = 0        while x >= 1:            rest = x % 10            residual = residual * 10 + rest            x /= 10        if tmp_x == residual:            return True        return False

 
0 0
原创粉丝点击