题目:

  Determine whether an integer is a palindrome. Do this without extra space.

Some hints:

  Could negative integers be palindromes? (ie, -1)

  If you are thinking of converting the integer to string, note the restriction of using extra space.

  You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?

思路:这题比较简单,可以把数字翻转与原数进行比对。需要注意的是负数的判定以及翻转之后可能会产生溢出的问题。

public class Solution {
public boolean isPalindrome(int x) {
if(x<0) return false;
long res=0;
long lx=x;
while(lx!=0){
res=res*10+lx%10;
lx/=10;
}
return res==x;
}
}

  

---恢复内容结束---

【LeetCode】9 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 3——Palindrome Number(回文数)

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

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

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

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

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

  5. LeetCode Problem 9:Palindrome Number回文数

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

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

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

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

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

  8. Palindrome Number 回文数

    判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出.     ...

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

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

随机推荐

  1. Linux系统下如何设置IP地址?

    Linux系统下如何设置IP地址?我们可以通过命令设定IP的方法,不过此方法的前提条件是用户需root权限.在linux系统的 /etc/sysconfig/network-script/ifcfg- ...

  2. Python之文件输入输出,

      文件输入与输出 • 打开文件返回文件对象 – file_object=open(file_name,access_mode='r') • 关闭文件对象 – file_object.close() ...

  3. 1.4 DVWA亲测文件上传漏洞

    Low 先看看源代码: <?php if(isset( $_POST[ 'Upload' ] ) ) { // Where are we going to be writing to? $tar ...

  4. C# 生成word 文档 代码 外加 IIS报错解决方案

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  5. js 实现ajax(get和post)

    get和post的区别:1.GET产生一个TCP数据包:POST产生两个TCP数据包. 对于GET方式的请求,浏览器会把http header和data一并发送出去,服务器响应200(返回数据): 而 ...

  6. cf706C(dp)

    题目链接:http://codeforces.com/problemset/problem/706/C 题意:给出n个字符串,反转第 i 个字符串需要花费 ai,问通过反转操作将n个字符串变成升序排列 ...

  7. 洛谷P2950 [USACO09OPEN]牛绣Bovine Embroidery

    P2950 [USACO09OPEN]牛绣Bovine Embroidery 题目描述 Bessie has taken up the detailed art of bovine embroider ...

  8. openinstall的免费服务对App推广有哪些帮助?

    想在微信中下载 App,需要“点击右上角打开浏览器”,太麻烦: 想深入查看微信分享内容,需要手动打开 App 搜索,不方便: 想给 App 做推广,Android 需要多个渠道人工打包,效率低: .. ...

  9. Vue2中实现微信分享支付功能

    Vue2中实现微信分享支付功能  近期做了一个微信公众号前后分离项目,前端采用Vue2开发,后端SpringBoot,今天迫不及待的来给大家分享一下这次在开发中遇到的一些坑以及解决办法. 在这里,一些 ...

  10. 制作windows启动盘

    ·首先:不要使用“老毛桃,大白菜,u深度,电脑店,u大师”等工具,国产流氓软件了解下. ·工具:UltraISO (自行下载)环境:Windows ·Windows 7微软原版无修改的系统镜像下载地址 ...