Leetcode 9[easy]---Palindrome Number
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.
思路:
题意简单,判断给定的整数是否为回文序列。以前写过一个code,今天改了一下使之逻辑性更强,这也算进步吧。
首先排除掉小于零的副整数. 剩余的整数进行如下操作:整数--string---首尾颠倒---整数,与原整数进行比较。说明:原整数的尾数为0的,因为在其后的操作中会丢失掉原整数尾部的0.