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.
package pack;
class Solution {
public boolean isPalindrome(int x) {
if(x <

本文探讨如何在不使用额外空间的情况下判断一个整数是否为回文数。考虑负数的情况,以及避免将整数转换为字符串带来的限制。同时,提到反转整数的方法,但要解决反转后可能溢出的问题,并提出更通用的解决方案。
订阅专栏 解锁全文
8951

被折叠的 条评论
为什么被折叠?



