LeetCode #9 迴文數

LeetCode #9 迴文數

思路

  • 轉換爲字符串做

代碼

class Solution:
    def isPalindrome(self, x: int) -> bool:
        st = str(x)
        for i in range(len(st)//2 + 1):
            if(st[i] != st[len(st)-i-1]):
                return False
        return True
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章