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. mysql 5.7.16 忘记root 密码 如何修改root密码

    今天在电脑上安装  mysql5.7.16 (压缩包)时,在初始化data文件夹之后,没有记住密码,DOS框没有显示,没办法,为了学习一下怎么修改密码,在网上找了好多方法去解决,最终还是解决了,下面来 ...

  2. 关于idea通过smalidea无源调试apk

    idea 14.0.2 可以使用 smalidea 0.03 单步时,只能按照源码中的行号(line xxx)指定的行跳动, 可以使用鼠标选中变量即时查看变量值 idea 16/17 可以使用smal ...

  3. php框架安装

    安装yii框架 跳转到composer.phar目录 cd C:\ProgramData\ComposerSetup\bin 安装yii2高级版 php composer.phar create-pr ...

  4. ASCII码查看

    字母对照表: ASCII可显示字符: ASCII控制字符:

  5. excle函数

    1.time函数 说明: https://support.office.com/zh-cn/article/time-%E5%87%BD%E6%95%B0-9a5aff99-8f7d-4611-845 ...

  6. c++ ActiveX基础1:使用VS2010创建MFC ActiveX工程项目

    1.ActiveX的基本概念 ActiveX控件可以看作是一个极小的服务器应用程序,它不能独立运行,必须嵌入到某个容器程序中,与该容器一起运行.这个容器包括WEB网页,应用程序窗体等... Activ ...

  7. 2.2.3 TableLayout(表格布局)

    3.如何确定行数与列数 ①如果我们直接往TableLayout中添加组件的话,那么这个组件将占满一行!!! ②如果我们想一行上有多个组件的话,就要添加一个TableRow的容器,把组件都丢到里面! ③ ...

  8. 映众全新游戏内存条发布:单条16GB 最高4000MHz

    近日,显卡与内存厂商映众(INNO3D)推出了一款全新的游戏内存条产品——iCHILL Memory. iCHILL Memory是DDR4内存,单条容量有4GB-16GB可选,内存频率有2400MH ...

  9. leetcode367--Valid Perfect Square

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  10. Python2.7-glob

    glob 模块,寻找所有匹配指定的模式的路径名,利用的是 Unix shell 的规则,可以在 Windows 环境下使用.模块是通过 os.listdir() 和 fnmatch.fnmatch() ...