leetcode 9. Palindrome Number

原创 2016年05月31日 22:04:52

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

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.

判断一个整数是否是回文数,负数返回false.

public class A9PalindromeNumber {
	public boolean isPalindrome(int x) {
        if(x < 0) return false;
        int m = x;
        long y = 0;
        while(m > 0) {
        	y = y * 10 + m % 10;
        	m /= 10;
        	if(y > Integer.MAX_VALUE)
        		return false;
        }
		return y == x ? true : false;
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

【python】【leetcode】【算法题目9—Palindrome Number】

题目原文: Determine whether an integer is a palindrome. Do this without extra space. (不用额外的空间来判断一个整形数字是不...

Leetcode #9 Palindrome Number

Source: https://leetcode.com/problems/palindrome-number/ 9. Palindrome Number Determine whether an ...
  • mu_jun
  • mu_jun
  • 2016年09月07日 01:45
  • 80

LeetCode : 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. “回文”是指正读反读都能读通的句子,它是古今中外都...

[LeetCode] #9 Palindrome Number

好久没有刷题了,现在开始刷LeetCode  GitHub : https://github.com/MummyDing/LeetCode Source : https://leetcode.com/...

LeetCode-9. Palindrome Number(回文数)

1.题目描述Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could n...

LeetCode OJ9 Palindrome Number 小结

Palindrome Number题目描述Determine whether an integer is a palindrome. Do this without extra space解题思路我们...

《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

009. Palindrome Number[E] Palindrome NumberE 问题 思路 思路1 思路2 问题:Determine whether an integer is a pali...

Leetcode_9_Palindrome Number

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41598031 Palindrome Number Det...

[LeetCode][9]Palindrome Number解析与StringBuilder.reverse()源码实现 -Java实现

Q: Determine whether an integer is a palindrome. Do this without extra space. A: 这个题目说实话,我是后半句没有看懂的...

LeetCode7~9 Reverse Integer/String to Integer (atoi)/Palindrome Number

一:Reverse Integer 题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode 9. Palindrome Number
举报原因:
原因补充:

(最多只允许输入30个字)