/*
查看网上的思路有两种:
1.每次取两边的数,然后进行比较
2.取数的倒置数,进行比较
*/
public boolean isPalindrome1(int x) {
if (x<0) return false;
//以四位数为例,取左边的数用的方法是/1000,取右边的数用的是%10
//注意每次取完两遍要更新数和位数
int len = 1;
int temp = x;
while (temp>=10)
{
len*=10;
temp/=10;
}
while (x!=0)
{
int left = x/len;
int right = x%10;
if (left!=right) return false;
len/=100;
//更新x的方法是先取出后几位,再去掉最右边
//%用来留下后边的,/用来留下前边的
x = (x%len)/10;
}
return true;
}
public boolean isPalindrome2(int x)
{
if (x<0) return false;
int a = 0;
int b = x;
while (b!=0)
{
a = a*10+b%10;
b%=10;
}
return (a==x);
}

[LeetCode]9. Palindrome Number判断回文数字的更多相关文章

  1. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  2. LeetCode 9 Palindrome Number(回文数字判断)

    Long Time No See !   题目链接https://leetcode.com/problems/palindrome-number/?tab=Description   首先确定该数字的 ...

  3. LeetCode 9. Palindrome Number (回文数字)

    Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...

  4. [LeetCode] 9. Palindrome Number 验证回文数字

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

  5. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  6. [LeetCode] Palindrome Number 验证回文数字

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

  7. [Leetcode] Palindrome number 判断回文数

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

  8. LeetCode OJ Palindrome Number(回文数)

    class Solution { public: bool isPalindrome(int x) { ,init=x; ) return true; ) return false; ){ r=r*+ ...

  9. LeetCode 9. Palindrome Number(回文数)

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

随机推荐

  1. docker centos容器无法yum

      问题 dockerfile yum -y install vim的时候一直未响应 但是在本地虚拟机centos7上运行则没问题   https://blog.csdn.net/jimiao_xxx ...

  2. java.util.UnknownFormatConversionException: Conversion = 'j' || Conversion = 'D' || Conversion = 'Y'

    执行内容: String a = "select * from j_question j where j.status = %s and j.title like '%java%'" ...

  3. getElementBy系列和querySelector系列的区别

    querySelector和querySelectorAll的用法和getElementBy大致一样,获取的时候带上符号,getElementBy获取的是元素的动态集合,querySelector获取 ...

  4. 第7.6节 Python中类的继承机制详述

    在本章第一节,介绍了面向对象程序设计的三个特征:封装.继承和多态,前面章节重点介绍了封装和多态,由于Python语言是多态语言,对象的类型不再由继承等方式决定,而由实际运行时所表现出的具体行为来决定, ...

  5. PyQt(Python+Qt)学习随笔:QTabWidget部件选项卡可用状态访问方法isTabEnabled、setTabEnabled

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTabWidget的每个选项卡及页面可设置是否可用,如果选项卡不可用时,则不能通过操作手工切换到该 ...

  6. Python正则表达式处理的组是什么?

    在学习正则表达式处理开始阶段,对于匹配对象的group数据没有理解,查了资料进行验证测试,终于理解了. 组其实与组匹配模式相关,就是在匹配的正则表达式中使用小括号"()"括起来的任 ...

  7. IDM 6.37.8 绿色特别版 (4月4日更新)

    Internet Download Manager,全球最流行的下载工具.Internet Download Manager (简称IDM) Windows 平台功能强大的多线程下载工具,国外非常受欢 ...

  8. Windows下MySQL无法启动万能解决方案

    MySQL启动报错 window10上安装了MySQL之前使用都是执行net start mysql 启动,执行net stop mysql关闭. 某天开始启动报错"MySQL 服务无法启动 ...

  9. 第三方模块Gulp

    1.第三方模块Gulp 基于node平台开发的前端构建工具. 将机械化操作编写成任务,想要执行机械化操作时执行一个命令,命令任务就能自动执行了.提高开发效率. 1)Gulp使用 ① 使用npm ins ...

  10. selenium.common.exceptions.WebDriverException: Message: 'chromedriver'解决

    相信很多第一次学习selenium的同学们也对这个异常不陌生了,但具体该如何解决这个bug呢? 主要的原因还是因为selenium模拟的客户端对浏览器的操作,但相应浏览器的驱动版本不匹配导致的. 为了 ...