[勇者闯LeetCode] 9. Palindrome Number

来源:互联网 发布:php实现sql防注入 编辑:程序博客网 时间:2024/04/29 07:17

[勇者闯LeetCode] 9. Palindrome Number

Description

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

Information

  • Tags: Math
  • Difficulty: Easy

Solution

class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        if x < 0 or (x != 0 and x % 10 == 0):            return False        a, b = 0, x        while b > a:            a, b = a * 10 + b % 10, b // 10        return a == b or a // 10 == b
0 0
原创粉丝点击