[LeetCode]009.Palindrome Number

Question

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.

Solution

  • C
1
2
3
bool isPalindrome(int x) {

}
  • C++
1
2
3
4
5
6
class Solution {
public:
bool isPalindrome(int x) {

}
};
  • Java
1
2
3
4
5
public class Solution {
public boolean isPalindrome(int x) {

}
}
  • JavaScript
1
2
3
4
5
6
7
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {

};
  • Python
1
2
3
4
class Solution:
# @param {integer} x
# @return {boolean}
def isPalindrome(self, x):
  • Swift
1
Hello World
坚持原创技术分享,您的支持将鼓励我继续创作!