Long Time No See !
 
 
首先确定该数字的位数。按照已知数字x对10进行多次求余运算,可以得到数字位数。
具体思路:
1、每次取出该数字的最高位和最低位进行比较。
2、如果不相等则直接返回FALSE,
3、如果相等修改x的值(去掉最高位也同时去掉最低位)其中去掉最高位可以通过求模运算,去掉最低位可以采用除以10
4、进行循环直到x的值不大于0为止
 
参考代码:
package leetcode;

/***
*
* @author pengfei_zheng
* 判断回文数字
*/
public class Solution09 {
public boolean isPalindrome(int x) {
if(x < 0) //小于0返回false
return false;
int len = 1;
while(x/len >= 10)
len *=10;//求出x的位数对应的pow(10,n)
while(x>0){
int left = x / len;//取x的最高位
int right = x % 10;//取x的最低位 if(left != right)//有不等则返回false
return false;
else {
x = (x % len) / 10;//修改x的值 求模运算去掉最高位 除法运算去掉最低位
len /= 100;//修改x的位数对应的pow(10,n)
}
}
return true;
}
};

LeetCode 9 Palindrome Number(回文数字判断)的更多相关文章

  1. 【LeetCode每天一题】Palindrome Number( 回文数字)

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

  2. leetcode 9 Palindrome Number 回文数

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

  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 3——Palindrome Number(回文数)

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

  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. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. LeetCode Valid Palindrome 有效回文(字符串)

    class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...

随机推荐

  1. SpringBoot和SpringCloud配置

    1.基本配置 #项目名称(访问路径) server.context-path=/manager #端口 server.port=8764 #session过期时间 server.sessionTime ...

  2. CocoaPods:说点关于它的

    CocoaPods安装和使用教程 安装及使用方法,这里有现成的,很细致,不再赘述(发音:zhuìshù,敲半天ao'shu,找不到这个词 =.=)   记录一下遇到的问题 1.CocoaPods 版本 ...

  3. 边框颜色为 tintColor 的 UIButton

    创建一个 UIButton 的子类,重写其方法: - (void)drawRect:(CGRect)rect { [[self layer] setCornerRadius:CORNER_RADIUS ...

  4. 查看cp进度,使用watch

    watch -n 1 -d du -sh dir 每隔1s查看当前目录所占空间大小

  5. web.py开发

    web.py需要使用python2.X,所以安装python版本2.7.9 web.py 是一个轻量级Python web框架,它简单而且功能强大 web.py安装 安装python (1)使用pip ...

  6. Java如何取得当前程序部署的服务器的IP

    1.问题:之前使用InetAddress.getLocalHost().getHostAddress()时,在开发机测试可以得到192.168.0.18这样的IP.但部署到linux服务器以后, 这个 ...

  7. opengl库区分:glut、freeglut、glfw、glew、gl3w、glad

    //oepngl库 opengl原生库 gl* 随opengl一起发布 opengl实用库 glu* 随opengl一起发布 opengl实用工具库glut glut* 需要下载配置安装(太老了!) ...

  8. OpenGL中的光照技术(翻译)

    Lighting:https://www.evl.uic.edu/julian/cs488/2005-11-03/index.html 光照 OpenGL中的光照(Linghting)是很重要的,为什 ...

  9. Ubuntu18.10安装网易云音乐(图文并茂!)

    听音乐,怎么少得了网易云音乐,下面我们在Ubuntu18.10上来安装下: 首先进入网易云音乐的下载页:https://music.163.com/#/download,选择下载Ubuntu版本: 我 ...

  10. mysql 日志操作

    https://www.cnblogs.com/dreamworlds/p/5478293.html http://www.jb51.net/article/76886.htm