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. Git钩子详解

    钩子 Git钩子是在Git仓库中特定事件发生时自动运行的脚本.可以定制一些钩子,这些钩子可以在特定的情况下被执行,分为Client端的钩子和Server端的钩子.Client端钩子被operation ...

  2. ORACLE 查看并修改最大连接数

    第一步,在cmd命令行,输入sqlplus,打开登录窗口,如下: 第二步,根据提示输入用户名与密码 请输入用户名:sys as sysdba 输入口令:******** 第三步,查看processes ...

  3. Alpha冲刺报告(4/12)(麻瓜制造者)

    今日完成的情况 江郑: 今天对数据库的需求部分进行了完善 邓弘立: 完成了首页界面UI 刘双玉: 基本完成商品信息发布接口 汪志彬: 尝试UI的设计 符天愉: 将登录接口部署到服务器上,结果Linux ...

  4. 【Python】os.path.isfile()的使用方法汇总

    方法一: # -*- coding:utf-8 -*- import os import sys from uiautomator import device as d filepath = r'E: ...

  5. 【openjudge】【搜索(bfs)】P4980拯救行动

    [描述:] 公主被恶人抓走,被关押在牢房的某个地方.牢房用N*M (N, M <= 200)的矩阵来表示.矩阵中的每项可以代表道路(@).墙壁(#).和守卫(x). 英勇的骑士(r)决定孤身一人 ...

  6. python-json模块扩展

    sort_keys=True, indent=4, separators=(',', ': ') 格式 json.dumps(response,sort_keys=True, indent=4, se ...

  7. MP实战系列(八)之SpringBoot+Swagger2

    SpringBoot一个原则,爱好编程的朋友们都知道,那就是"习惯优于配置". 今天一上来主要说的还是代码,个人比较喜欢来的实战系列的,不过有的时候还是比较偏重于理论,理论是造轮子 ...

  8. kvm安装配置使用centos6.5

    # yum -y install kvm virt-* libvirt  && yum -y groupinstall Virtualization 'Virtualization C ...

  9. JAVA框架 Spring 和Mybatis整合(动态代理)

    一.使用传统方式的dao的书写方式,不建议.目前采用的是动态代理的方式交给mybatis进行处理. 首先回顾下动态代理要求: 1)子配置文件的中,namespace需要是接口的全路径,id是接口的方法 ...

  10. C#中的委托(二)

    一.Action<T>和Func<T>委托 除了上篇描述的为每个参数和返回类型定义一个新委托类型之外,还可以使用Action<T>和Func<T>委托. ...