Palindrome Number problem

Leetcode problem: https://leetcode.com/problems/palindrome-number/

Notes: It ain't much but it's honest work. Cast the int into a string. Reverse the string. Compare the reversed string to the original int that was cast. If the two are same then the original int was a palindrome otherwise it wasn't.

Solution:

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


要查看或添加评论,请登录

Vijay Kumar的更多文章

社区洞察

其他会员也浏览了