009-palindrome number

palindrome number

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

click to show spoilers.

Some hints:
Could negative integers be palindromes? (ie, -1)

If you are thinking of converting the integer to string, note the restriction of using extra space.

You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?

There is a more generic way of solving this problem

簡(jiǎn)單。。

class Solution:
    def isPalindrome(self, x: int) -> bool:
        return str(x) == str(x)[::-1]

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,872評(píng)論 0 10
  • 第周周檢視 沒有反思的人生不值得過。 本周溫馨時(shí)刻和點(diǎn)滴幸福。 圖片發(fā)自簡(jiǎn)書App (我曾經(jīng)去過這個(gè)地方佛羅倫薩,...
    呼和浩特張勇閱讀 142評(píng)論 0 0
  • 來沈陽富家居科技有限公司,學(xué)習(xí)培訓(xùn),確定自己的工作方向: 第一,做品牌,做運(yùn)營(yíng),做盤子,求助于投資人,(重點(diǎn)) 第...
    呂占陽閱讀 131評(píng)論 0 0
  • 20歲開始 人一定要學(xué)會(huì)照顧好自己 能獨(dú)立去做一些事
    膩R閱讀 146評(píng)論 0 0
  • 第一章 逃婚 逃婚。 對(duì)本姑娘來說簡(jiǎn)直是小case。 “……與她相守一生,白頭偕老。新郎,你愿意嗎?”“我愿意”...
    怪貓阿柒閱讀 451評(píng)論 0 0

友情鏈接更多精彩內(nèi)容