判断一个数字是否是回文数,尝试不用其他额外空间。
注意:
负数也有可能成为回文数吗?
如果你想让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. windows internal读书笔记

    程序:指一个静态的指令序列,而进程则是一个容器,其中包含了当执行一个程序特定实例时所用到的各种资源.

  2. spark-sql

    本文用到的测试数据person.txt lijing 29 guodegang 45 heyunwei 30 yueyunpeng 100 rdd的分区数量,读取hdfs文件,默认是文件个数 rdd生 ...

  3. LIS n*log(n)的理解

    很多时候lis 用二分的方法比较方便 这里写一下他的原理 这里仅对严格的最长上升子序列做讨论 这里有两个数列  一个数列是 原串的数列 a1-an  另一个数列是最长上升子序列辅助数列 s数列的长度为 ...

  4. php 初学笔记

    1.变量定义和使用 php中定义变量名为:$aa 在类中一般定义一个新变量需要添加var字,如var $aaa. 但是过程或函数中是不需要添加var 关键字,如$aaa=$_POST['aaaa'], ...

  5. wordpress禁止调用官方Gravatar头像调用ssl头像链接提升加载速度

    在主题中的functions.php文件末尾加上以下代码即可(外观>编辑>functions.php) //官方Gravatar头像调用ssl头像链接 function get_ssl_a ...

  6. jsonp跨域请求学习笔记

    前言 ajax,用苍白的话赞扬:很好. 我们可以使用ajax实现异步获取数据,减少服务器运算时间,大大地改善用户体验:我们可以使用ajax实现小系统组合大系统:我们还可以使用ajax实现前端的优化.( ...

  7. cf C. Insertion Sort

    http://codeforces.com/contest/362/problem/C #include <cstdio> #include <cstring> #includ ...

  8. POJ 1225 Substrings

    http://poj.org/problem?id=1226 题意:给定n个串.求一个最长的串,使得这个串或者其反串在每个串中都出现过? 思路:先在大串里面加入正反串,然后二分,判定即可. #incl ...

  9. Codeforces 459E Pashmak and Graph

    http://www.codeforces.com/problemset/problem/459/E 题意: 给出n个点,m条边的有向图,每个边有边权,求一条最长的边权上升的路径的长度. 思路:用f存 ...

  10. 自制单片机之二-----AT89S51ISP下载线的制做

    最小系统板做好了,接下来就是做根ISP下载线了.否则程序怎么写到AT89S51芯片里呢? 先来认识一下AT89S51上ISP(在线编程)功能脚的定义 看上图的左边AT89S51引脚图的P1.5.P1. ...