0
1

More than 3 years have passed since last update.

leet code Palindrome Number(easy)

Posted at

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

brute force

class Solution:
    def isPalindrome(self, x: int) -> bool:
        for i in range(len(str(x))):
            x = str(x)
            if x[i] != x[len(str(x))-i-1]:
                return False
        if int(x) < 0:
            return False
        else:
            return True

bit faster solution

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0:
            return False
        if str(x) != str(x)[::-1]:
            return False
        else:
            return True
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1