这题要求不能使用额外的空间,我也就没做,看了下别人的代码,挺有意义的一道题目,出坏了。

解题思路:从右往左颠倒过来,看看这个值和原来的x值是不是一样,最后还要注意像20这种情况,也是的

public boolean isPalindrome(int x) {
if (x<0 || (x!=0 && x%10==0)) return false;
int rev = 0;
while (x>rev){
rev = rev*10 + x%10;
x = x/10;
}
return (x==rev || x==rev/10);
}

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题解 9. Palindrome Number

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

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

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

  5. C# 写 LeetCode easy #9 Palindrome Number

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

  6. leetcode 第九题 Palindrome Number(java)

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

  7. LeetCode(9) - Palindrome Number

    题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...

  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. Java多线程系列 JUC锁08 LockSupport

    转载 http://www.cnblogs.com/skywang12345/p/3505784.html https://www.cnblogs.com/leesf456/p/5347293.htm ...

  2. 第一篇 先用socket模拟web服务器

    一.用socket来模拟网站访问 socket为python2.7 #!/usr/bin/env python # -*- coding:utf-8 -*- import socket def han ...

  3. TCP相关知识总结

    参考: http://coolshell.cn/articles/11564.html http://coolshell.cn/articles/11609.html TCP头格式 接下来,我们来看一 ...

  4. shell 字符串操作

    赋值: str="i am vincen" 计算字符串长度: ${#str} 字符串截取: ${str:2} ${str:2:3} 从开头删除匹配的子串: ${str#" ...

  5. Delphi 的进制转换

    1.10进制转16进制 intTohex(10,4);  //第一个参数为要转换的数据,第二个参数为要转换后的16进制位数:得到:000A; 2. 16进制转10进制 strToInt('$'+'64 ...

  6. windows8.1下安装msi文件报错

    新安装了win8.1系统体验体验,可是安装msi文件的软件报internal error2502和2503错误,可以换一种安装方式. 不是直接点开安装,如图所示打开命令提示符: 使用msiexec / ...

  7. jQuery 开发一个简易插件

    jQuery 开发一个简易插件 //主要内容 $.changeCss = function(options){ var defaults = { color:'blue', ele:'text', f ...

  8. thinkphp3.2新部署是错

    下载好thinkphp3.2,使用M或者D方法是,报FILE: tp\ThinkPHP\Library\Think\Db.class.php LINE: 42 可能的错误是,配置文件中没有配置数据库连 ...

  9. linux应用之make命令详解

    从源代码安装过软件的朋友一定对 ./configure && make && make install 安装三步曲非常熟悉了.然而究竟这个过程中的每一步幕后都发生了些什 ...

  10. L99

    You're not obligated to win. You're obligated to keep trying.你不一定要获胜,但你必须不断尝试.He announced an expans ...