1. 程式人生 > >leetcood學習筆記-9

leetcood學習筆記-9

筆記 urn leet elf nbsp ima def png 數字反轉

題目描述

技術分享圖片

方法一:轉換為字符串

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

方法二;數字反轉

class Solution:
    def isPalindrome(self, x: int) -> bool:
        
if x<0: return False a,res=x,0 while x: x,mod = x//10,x%10 res=res*10+mod return a == res

leetcood學習筆記-9