/* 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. xml学习笔记一(概述)

    XML 被设计用来传输和存储数据. HTML 被设计用来显示数据. 什么是 XML? XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 ...

  2. PIP安装Python的scipy,scrapy等包出现“failed building wheel for xxx”问题解决办法

    1.在这里下载对应的.whl文件,注意别改文件名! http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Ctrl + F,输入lxml,找到下面这段 Lxm ...

  3. eclipse中web工程新建jsp文件报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    web工程中新建jsp文件提示:The superclass "javax.servlet.http.HttpServlet" was not found on the Java ...

  4. 【extjs】 Extjs中的Ext.grid.Panel隐藏列会显示在表头中解决方法

    在Extjs中的GridPanel会有这样的情况,隐藏列会显示在menuDisabled中,但是这个一般没有什么用处,只是用于后台取值的作用,感兴趣的朋友可以了解下啊,希望本文对你有所帮助   在Ex ...

  5. HackerRank "Array and simple queries" !

    The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here ...

  6. Linux下编译OpenSSL

    编译环境 操作系统: Red Hat Enterprise Linux Server release 5.4 64-bit 编译工具: gcc (GCC) 4.1.2 20080704 (Red Ha ...

  7. Learning Puppet — Resources and the RAL

    Learning Puppet — Resources and the RAL Welcome to Learning Puppet! This series covers the basics of ...

  8. hist和bar画图关系

    1.hist是绘制直方图,直方图显示了数据值的分布情况.  1>n = hist(Y,n)      将向量Y中的元素分到n个等间隔的范围内(默认为10个间隔),并返回每个范围内元素的个数作为一 ...

  9. iphone dev 入门实例3:Delete a Row from UITableView

    How To Delete a Row from UITableView I hope you have a better understanding about Model-View-Control ...

  10. FB Flash Builder 安装错误 ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x86): Install failed

    这个问题很可能是你的 Microsoft Visual C++ 2010 Redistributable Package (x86) 太新的缘故,所以无法安装成功,导致最终的失败. 在控制面板-程序和 ...