Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

Example 1:

Input: 121
Output: true

Example 2:

Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.

Example 3:

Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

Follow up:

Coud you solve it without converting the integer to a string?

public boolean isPalindrome(int x) {
int[] nums=new int[32];
int i=0;
if(x<0)//负数或 最后一位为0(后半句不严谨,单独0是对称的)
return false;
while(x/10>0){
nums[i]=x%10;
i++;
x=x/10;
}
nums[i]=x%10;
int len=0;
for(i=31;i>=0;i--){
if(nums[i]>0){
len=i;//数字位数
break;
}
}
for(i=0;i<=len/2;i++){
if(nums[i]!=nums[len-i])
return false;
}
return true;
}

 

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. 【LeetCode】9 Palindrome Number 回文数判定

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

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

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

随机推荐

  1. 【工具推荐】截图工具 Snipaste

    0. 说明 [官网介绍] Snipaste 是一个简单但强大的截图工具,也可以让你将截图贴回到屏幕上!下载并打开 Snipaste,按下 F1 来开始截图,再按 F3,截图就在桌面置顶显示了.就这么简 ...

  2. 安全之路 —— C/C++开3389端口(远程终端)

    简介 在渗透测试中开启对方电脑的3389端口是入侵者加入对方计算机账户后要想直接控制对方计算机的必须步骤,即开启对方计算机的远程终端功能,不同的Windows系统要开启3389需要修改不同的注册表项, ...

  3. 【Ansible 文档】【译文】Windows 支持

    see also:List of Windows Modules Windows Support Windows 支持 Windows: How Does It Work Windows:如何工作 正 ...

  4. PHP实现微信发红包功能2

    <?php class wxPay { //配置参数信息 const SHANGHUHAO = "1430998xxx";//商户号 const PARTNERKEY = & ...

  5. PHP缓存锁原理及利用

    原文链接:https://blog.csdn.net/tim_phper/article/details/54949404 概述: 项目当中经常要考虑数据高并发的情况,为了避免并发导致出现一些资源重复 ...

  6. django博客项目-设置django为中文语言

    找到项目级别里面的setting文件,修改如下配置 """ LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' & ...

  7. A Theoretical Analysis of Feature Pooling in Visual Recognition

    这篇是10年ICML的论文,但是它是从原理上来分析池化的原因,因为池化的好坏的确会影响到结果,比如有除了最大池化和均值池化,还有随机池化等等,在eccv14中海油在顶层加个空间金字塔池化的方法.可谓多 ...

  8. jquery mouseover与mouseenter区别

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. Scala--文件和正则表达式

    一.读取行 import scala.io.Source val source = Source.fromFile("D:\\documents\\Scala\\MyDemo\\t.txt& ...

  10. redis系列--redis4.0深入持久化

    前言 在之前的博文中已经详细的介绍了redis4.0基础部分,并且在memcache和redis对比中提及redis提供可靠的数据持久化方案,而memcache没有数据持久化方案,本篇博文将详细介绍r ...