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

简单。。

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,150评论 0 10
  • 第周周检视 没有反思的人生不值得过。 本周温馨时刻和点滴幸福。 图片发自简书App (我曾经去过这个地方佛罗伦萨,...
    呼和浩特张勇阅读 884评论 0 0
  • 来沈阳富家居科技有限公司,学习培训,确定自己的工作方向: 第一,做品牌,做运营,做盘子,求助于投资人,(重点) 第...
    吕占阳阅读 819评论 0 0
  • 20岁开始 人一定要学会照顾好自己 能独立去做一些事
    腻R阅读 845评论 0 0
  • 第一章 逃婚 逃婚。 对本姑娘来说简直是小case。 “……与她相守一生,白头偕老。新郎,你愿意吗?”“我愿意”...
    怪猫阿柒阅读 3,097评论 0 0