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. iOS: Sorted Array with Compare

    Question(提问): What I want to do seems pretty simple, but I can't find any answers on the web. I have ...

  2. Xcode 文档注释

    首先要下载一个服务:[下载地址]这是一个老外写的工作流,解压缩,然后双击,安装一下, 选择xcode —> services —> services perference 安装完就会在右边 ...

  3. YFCMF 问题

    1.菜单不见了,yf.php  (main 改为0 ) function tagMenu $parseStr .='echo get_menu("main","'.$to ...

  4. 使用DataSource绑定一维数组时,DataTextField只需绑定空字符串

    方法定义: public static void InitDropDownList(DropDownList ddl, bool isAddTopItem, DropDownList ddlSub, ...

  5. SpringMVC工作原理详解

    先来看一下什么是 MVC 模式 MVC 是一种设计模式. MVC 的原理图如下: SpringMVC 简单介绍 SpringMVC 框架是以请求为驱动,围绕 Servlet 设计,将请求发给控制器,然 ...

  6. snmp简单使用

    preface snmp 不多说 环境介绍 1.使用CentOs7的系统,内核版本为3.10.0-123.el7.x86_64 2.ip地址为192.168.56.12 安装snmp 1.yum安装: ...

  7. BarTender复合条形码中的分隔符模式详解

    在BarTender 10.1中,支持使用BarTender分隔符模式的复合条形码符号体系包括GS1 Composite和GS1 DataBar (RSS).本文小编给大家详细讲解BarTender分 ...

  8. C#常用数据加密类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Sec ...

  9. re.match re.search re.findall区别

    re正则表达式里面,常用的三种方法的区别. re.macth和search匹配得到的是match对象,findall得到的是一个列表. match从字符串开头开始匹配,search返回与正则表达式匹配 ...

  10. [Scikit-learn] 1.1 Generalized Linear Models - Lasso Regression

    Ref: http://blog.csdn.net/daunxx/article/details/51596877 Ref: https://www.youtube.com/watch?v=ipb2M ...