题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false。题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了reverse integer,我们就可以利用reverse integer得到一个reverse number,然后和输入作对比,如果与输入一致,则返回true,如果不一致,则返回false。代码如下:

 public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) return false;
int reverse = reverse(x);
if (reverse == x) return true;
else return false;
} private int reverse(int x) {
int reverse = 0;
while (x > 0) {
reverse = reverse * 10 + x % 10;
x = x / 10;
}
if (reverse < 0) return -1;
else return reverse;
}
}

LeetCode(9) - Palindrome Number的更多相关文章

  1. leetcode bug & 9. Palindrome Number

    leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...

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

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

  3. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  4. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

  5. 【LeetCode】9. Palindrome Number (2 solutions)

    Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...

  6. C# 写 LeetCode easy #9 Palindrome Number

    9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...

  7. [LeetCode 题解]:Palindrome Number

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine ...

  8. 【一天一道LeetCode】#9. Palindrome Number

    一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...

  9. LeetCode Problem 9:Palindrome Number回文数

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

随机推荐

  1. linux系统的权限介绍

    让我们用t o u c h命令创建一个文件:$ touch myfile现在对该目录使用ls -l命令: 我们已经创建了一个空文件,正如我们所希望的那样,第一个横杠告诉我们该文件是一个普通文件.你将会 ...

  2. python类的简单介绍

    类是面向对象编程的核心, 它扮演相关数据及逻辑的容器角色.它们提供了创建“真实”对象(也就是实例)的蓝图.因为Python 并不强求你以面向对象的方式编程(与Java 不同), 此刻你也可以不学习类. ...

  3. 《c程序设计语言》读书笔记--字符串比较

    举例如下: char a[10]; 1.定义的时候直接用字符串赋值 char a[10]="hello"; 注意:不能先定义再给它赋值,如  char a[10];  a[10]= ...

  4. Python代码编辑器

    PyCharm Community 说到PyCharm Community,我们就会想到它是一款免费的开源Python代码编辑器,不过这也是事实啦.PyCharm Community为我们提供了轻量级 ...

  5. c#换ip代理源码

    很多朋友都想如何提高自己的网站流量,可是都没有什么好的办法 经过很长时间的研究,在C#中实现了,当然了,这部分代码其中一部分是网上的,不是原创. using System; using System. ...

  6. eclipse 报错 import ... cannot be resolved 处理方法

    项目上右键,properties, 找java build path,切到libraies标签,将爆红的jdk编辑一下,选用你需要的jdk版本,一般1..我看你类的httpServlet报错,也是这个 ...

  7. shell 括号学习

    http://blog.csdn.net/tttyd/article/details/11742241 http://tldp.org/LDP/abs/html/loops1.html

  8. gridview自定义表头

    gridview为我们提供了丰富的接口,用于满足自定义需求. 通常asp:gridview会根据绑定的列Columns自动生成表头,展现在前台元素. 序号 类别 有时候需要复杂一些的表头. 序号 类别 ...

  9. ORA-10456:cannot open standby database;media recovery session may be in process

    http://neeraj-dba.blogspot.com/2011/10/ora-10456-cannot-open-standby-database.html   Once while star ...

  10. 【转】Github轻松上手5-站在巨人的肩膀上(Fork)

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzj3.html 有时候你可能想给别人的项目出把力,或者想以别人的项目作为自己项目的起点,在Github里 ...