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. Windows Server 2012 R2 创建AD域

        前言 我们按照下图来创建第一个林中的第一个域.创建方法为先安装一台Windows服务器,然后将其升级为域控制器.然后创建第二台域控制器,一台成员服务器与一台加入域的Win8计算机. 环境 网络 ...

  2. kettle性能优化

    普通开发电脑,如果没有网络查询步骤,kettle正常的速度应该在3000~20000条/秒.如果速度在2000条/秒一下,就可能需要调优. 性能优化的方式包括如下几种: 1.通过改变开始复制的数量(针 ...

  3. MySQL基础之 AUTO_INCREMENT

    AUTO_INCREMENT AUTO_INCREMENT是mysql唯一扩展的完整性约束,当为数据库表中插入新纪录时,字段上的值会自动生成唯一的ID,再具体设置AUTO_INCREMENT约束时,一 ...

  4. VS 0x80041FEB

    在打开from设计界面时,报错. 解决方法:将项目中Properties文件中licenses.licx删除,重新建立一个空的licenses.licx文件放到项目中. 重新打开界面,解决

  5. Python3编写网络爬虫03-正则表达式的使用

    一.正则表达式(处理字符串强大的工具,有特定的语法结构)功能:实现字符串的检索,替换,匹配验证实例: 地址:http://tool.oschina.net/regex/ #测试文本Hello,my p ...

  6. 实例化list

    List<String> lists = new ArrayList<String>();list.add("123");

  7. CentOS7创建本地YUM源的三种方法

    这篇文章主要介绍了CentOS7创建本地YUM源的三种方法,本文讲解了使用CentOS光盘作为本地yum源.如何为CentOS创建公共镜像.创建完全自定义的本地源等内容,需要的朋友可以参考下     ...

  8. BeiDou开源项目

    本文主要围绕着BeiDou是什么及其安装和快速开始等两个方面,希望能够对初学者和对此感兴趣的朋友有所帮助. 一. BeiDou是什么 它是服务器呈现的React应用程序的同构框架 特征如下: ✔︎高性 ...

  9. 真实的物理机安装Centos7系统后网卡只有lo没有eno1的解决办法:实际上是物理机未安装网驱动卡

    问题症状: 我真实的物理机安装Centos7系统后,在/etc/sysconfig/目录下查看,发现网卡只有lo没有eno1,出现该问题的实际原因是物理机未安装网驱动卡. 解决办法: 不多说了,让我们 ...

  10. Advanced Electronic Engineer

    Job Title Advanced Electronic Engineer Job Description In this role, you have the opportunity to Be ...