判断一个数字是否是回文数,尝试不用其他额外空间。
注意:
负数也有可能成为回文数吗?
如果你想让int转为string,注意不用其他空间这个约束。
你也可以翻转一个int,但是有可能会溢出。
 
 
 public class Solution {
public boolean isPalindrome(int x) {
if(x<0) return false; int temp = x, reverseX = 0;
while (temp > 0) {
reverseX = reverseX * 10 + temp % 10;
temp /= 10;
}
return x == reverseX;
}
}

Palindrome Number 回文数的更多相关文章

  1. leetcode 9 Palindrome Number 回文数

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

  2. LeetCode Problem 9:Palindrome Number回文数

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

  3. Leetcode 3——Palindrome Number(回文数)

    Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...

  4. [LeetCode]9. Palindrome Number回文数

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

  5. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  6. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  7. 【LeetCode】9 Palindrome Number 回文数判定

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...

  8. 9. Palindrome Number 回文数的判断

    [抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...

  9. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

随机推荐

  1. C#操作iframe

    <iframe id="cl" name="clf" src="xianshi.aspx" runat="server&qu ...

  2. Dalvik指令集

    类型 语法 含义 V void,只用于返回值类型 Z boolean B byte S short C char I int J long F float D double L Java类类型 [ 数 ...

  3. window程序设计1

    int WINAPI WinMain(HINSTANCE HInstance,HINSTANCE HPreInstance,LPSTR szCmdLine,int CmdShown) { Massag ...

  4. HDU 2063 裸奔的二分图最大匹配

    #include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#inc ...

  5. Go语言之defer

    defer语句被用于预定对一个函数的调用.我们把这类被defer语句调用的函数称为延迟函数.注意,defer语句只能出现在函数或方法的内部. 一条defer语句总是以关键字defer开始.在defer ...

  6. Membership添加验证码登录

    1.在公共类ImageHelper中编写公共方法,产生随机验证码 /// <summary> /// 产生随机验证码 /// </summary> /// <return ...

  7. Linux的标准输出、标准错误输出、nohup

    1.在bash中标准输出可以用1来表示:通常来说这个1可以省略: 如./xxx >/dev/null 和 ./xxx 1>/dev/null 是一个意思 2.在bash中标准错误输出可以用 ...

  8. Thinking in Java——笔记(21)

    Concurrency However, becoming adept at concurrent programming theory and techniques is a step up fro ...

  9. Spring MVC 和Struts2对比

    Spring MVC和Struts2的区别: 1. 机制:spring mvc的入口是servlet,而struts2是filter,这样就导致了二者的机制不同. ​2. 性能:spring会稍微比s ...

  10. Unity3d有关图形尺寸大小的注意事项

    主要参考了官方文档,然后根据个人的理解撰写该文.Unity3D支持的图形文件格式有 PSD, TIFF, JPG, TGA, PNG, GIF, BMP, IFF, PICT(但根据本人的亲手测试,U ...