Leetcode#9 Palindrome Number

less than 1 minute read

Published:

https://leetcode.com/problems/palindrome-number/description/

Solution:

class Solution {
    public:
        bool isPalindrome(int x) {
            if (x==0)
                return true;
            if (x < 0 || x%10 == 0)
                return false;

            int y = 0;
            int xx = x;
            while (xx>0) {
                y = y * 10 + xx%10;
                xx = xx/10;
            }
            if (x == y)
                return true;

            return false;
        }
};