题目:

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

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?

思路:这题比较简单,可以把数字翻转与原数进行比对。需要注意的是负数的判定以及翻转之后可能会产生溢出的问题。

public class Solution {
public boolean isPalindrome(int x) {
if(x<0) return false;
long res=0;
long lx=x;
while(lx!=0){
res=res*10+lx%10;
lx/=10;
}
return res==x;
}
}

  

---恢复内容结束---

【LeetCode】9 Palindrome Number 回文数判定的更多相关文章

  1. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  2. Leetcode 3——Palindrome Number(回文数)

    Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...

  3. [LeetCode]9. Palindrome Number回文数

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  4. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  5. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  6. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  7. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  8. Palindrome Number 回文数

    判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出.     ...

  9. 9. Palindrome Number 回文数的判断

    [抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...

随机推荐

  1. Spring入门第九课

    使用外部属性文件 在配置文件里面配置Bean时,有时需要在Bean的配置里面混入系统部署的细节信息(例如:文件路径,数据源配置信息等)而这些部署细节实际上需要和Bean配置相分离. Spring提供了 ...

  2. monkey无规则压力测试

    例:monkey -p com.tencent.mtaexample -s 23  --throttle 100 --ignore-crashes --ignore-timeouts -v -v -v ...

  3. Gym - 100851A Adjustment Office(O(1)求行列和)

    Adjustment Office Gym - 100851A 2       3       4 3       4       5 4       5       6 n<=10^6,q&l ...

  4. 30个物联网传感器小实验:三行代码点亮LED灯

    30个物联网传感器小实验:三行代码点亮LED灯 三行代码点亮LED灯 LED灯闪烁 LED灯调亮度 LED淡入淡出 不写一行代码点亮LED灯 全彩RGB灯 面包板 30个物联网传感器小实验:三行代码点 ...

  5. Scipy实现图片去噪

    先贴要处理的图片如下 由图片显示可知: # 图片中存在噪声点,白色的圆环# 圆环上的数据和圆环里面和外面不同,所以可以显示出肉眼可识别的图片# 波动# 存在噪声的地方,波动比较大 # 傅里叶变换可以将 ...

  6. 洛谷P3768 简单的数学题(莫比乌斯反演+狄利克雷卷积+杜教筛)

    传送门 不会…… 两篇加在一起都看不懂…… https://www.cnblogs.com/cellular-automaton/p/8241128.html https://www.luogu.or ...

  7. django后台管理系统(admin)的简单使用

    目录 django后台管理系统的使用 检查配置文件 检查根urls.py文件 启动项目,浏览器输入ip端口/admin 如: 127.0.0.1/8000/admin 回车 注册后台管理系统超级管理 ...

  8. 基于ZFAKA二次开发,添加PayJS支付渠道

    项目地址:https://github.com/hiyouli/payjs-for-zfaka 关于ZFAKA,请移步:ZFAKA 免费.安全.稳定.高效的发卡系统,值得拥有! 演示地址:http:/ ...

  9. 重启centOS丢失nginx.pid导致无法启动nginx的解决方法

    目录 找到nginx 找到nginx的配置文件 拼接命令,启动nginx Nginx指令拓展知识(中英对照): tags: centOS linux nginx categories: 服务器 找到n ...

  10. java 性能调优和GC

    JAVA 性能调优和GC http://blog.csdn.net/gzh0222/article/details/7663181 JAVA GC调优手记 http://blog.csdn.net/f ...