Leetcode Python Palindrome Number

来源:互联网 发布:java list 相同的元素 编辑:程序博客网 时间:2024/05/20 13:14

题目链接:

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


class Solution:    # @return a boolean    def isPalindrome(self, x):        i = 0        k = 0        temp1= x        temp2= x        if x < 0:            return False                while(temp1):            temp1 = temp1 / 10            i = i+1        while(i):            k = k+ temp2%10 * 10**(i-1)            temp2 = temp2/10            i = i-1        if k == x:            return True        else:            return False


0 0
原创粉丝点击