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

click to show spoilers.

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?

There is a more generic way of solving this problem.

Subscribe to see which companies asked this question   */9. Palindrome Number


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

  

9. Palindrome Number的更多相关文章

  1. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  2. 有趣的数-回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  3. No.009 Palindrome Number

    9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...

  4. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

    9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...

  5. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  6. HDU 5062 Beautiful Palindrome Number(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...

  7. Reverse Integer - Palindrome Number - 简单模拟

    第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...

  8. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

  9. LeetCode--No.009 Palindrome Number

    9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...

随机推荐

  1. win7 关于远程桌面登陆的方法,相应服务的启动

    转自:http://blog.csdn.net/ningfuxuan/article/details/7519476 远程登陆电脑,对远程电脑的设置 (1)首先要启动远程电脑中的Remote Desk ...

  2. 日期转换工具类 CommUtil.java

    package com.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.ut ...

  3. yii 主从数据库分离-转载http://www.yiichina.com/doc/guide/2.0/db-dao

    数据库复制和读写分离 很多数据库支持数据库复制 database replication来提高可用性和响应速度. 在数据库复制中,数据总是从主服务器 到 从服务器. 所有的插入和更新等写操作在主服务器 ...

  4. 详解@Autowired、@Qualifier和@Required

    A.@Autowired org.springframework.beans.factory.annotation.Autowired public @interface Autowired Mark ...

  5. [linux] linux 破解版confluence安装

    OS  centos 6.5  需要的安装包如下: jre-7u67-linux-x64.rpm atlassian-confluence-5.4.4-x64.bin mysql-connector- ...

  6. 读书笔记:Sheldon Ross:概率论基础教程:随机变量

    例1b 一个坛子里装有编号1-20的球,无放回抽取3个,取出球中至少一个号码大于等于17的概率是多少? 除了书上的解法外,还有一种解法: 考虑相反的情况:三个球的号码都小于17. 第一次从编号1-16 ...

  7. android学习笔记46——File存储

    File存储--IO操作文件 openFileOutput.openFileInput Context提供了如下两个方法来打开本应用程序的数据文件夹里面的文件IO流. 1.FileInputStrea ...

  8. ResultSet的getInt(),getString()方法

     数据库tt的examstudent数据表如下:   在MySQL中执行查询语句如下: ResultSet rs = null; String sql="SELECT flow_id,Typ ...

  9. Mysql游标的简明写法

    -- cursor 游标/*declare 声明; declare 游标名 cursor for select_statement;open 找开; open 游标名fetch 取值; fetch 游 ...

  10. POJ题目分类

    POJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一 ...