9. Palindrome Number
Difficulty: Easy
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.
My Solution
以12321为例
rev 0 1 12
x 12321 1232 123
1 | class Solution { |