/*
查看网上的思路有两种:
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. 03-Python里字符串的常用操作方法二

    1.lstrip():删除左侧空白字符 实例: my_str = ' hello world and my and test and python ' # 原始字符串 print(my_str) # ...

  2. fist-第九天冲刺随笔

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...

  3. Verilog单周期CPU(未完待续)

    单周期CPU:指令周期=CPU周期 Top模块作为数据通路 运算器中有ALU,通路寄存器(R1.R2.R3.R4),数据缓冲寄存器(鉴于书上的运算器只有R0)........... 此为ALU和通用寄 ...

  4. 浅尝 Elastic Stack (一) Elasticsearch、Kibana、Beats 安装

    Elastic Stack 包括 Elasticsearch.Kibana.Beats 和 Logstash,也称为 ELK Stack.能够安全可靠地获取任何来源.任何格式的数据,然后实时地对数据进 ...

  5. 解决 spring-integration-mqtt 频繁报 Lost connection 错误

    问题描述 在之前的博客介绍了如何在 Spring Boot 集成 MQTT,后面使用中没有发现问题,最近发现一直报错: Lost connection: Connection lost; retryi ...

  6. android studio报butterknife错误

    Error:Execution failed for task ':shipper:javaPreCompileDebug'.> Annotation processors must be ex ...

  7. 老猿学5G扫盲贴:与用户和终端相关的名词UE、SUPI、GPSI、PEI

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 和4 ...

  8. 第7.26节 Python中的@property装饰器定义属性访问方法getter、setter、deleter 详解

    第7.26节 Python中的@property装饰器定义属性访问方法getter.setter.deleter 详解 一.    引言 Python中的装饰器在前面接触过,老猿还没有深入展开介绍装饰 ...

  9. 第14章 web前端开发小白学爬虫结束语

    老猿学爬虫应该是2019年7月初开始的,到现在2个多月了,有段时间了,这部分一直是老猿期待能给大家带来收获的,因为老猿爬虫实战应用的场景与网上老猿已知的场景基本都不一样,是从复用网站登录会话信息来开发 ...

  10. PyQt(Python+Qt)学习随笔:Qt Designer中toolBar的orientation属性和iconSize属性

    orientation属性 orientation属性用于确认工具栏是水平方向还是垂直方向,这个属性对于QMainWindow中的工具栏来说没有意义,因为QMainWindow中的工具栏支持在上下左右 ...