niuworld/LeetCodeSolution

9.Palindrome Number

Opened this issue · 0 comments

Question:

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

Solution:

class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0 || x > INT_MAX || x < INT_MIN)
          return false;
          int rev = 0;
          int x_copy=x;
          while(x != 0){
            rev = rev * 10 + x % 10;
            x = x/10;
          }
          if(rev == x_copy)
          return true;
          else 
          return false;

    }
};