Easy C++ Solution


  • 0
    R
    class Solution {
    public:
        bool isPalindrome(int num) {
            if (num < 0)
                return false;
            
            long tenPow = 1;
            while (tenPow <= num){
                tenPow *= 10;
            }
            tenPow /= 10;
            
            while (tenPow > 1){
                int y = (num/tenPow);
                if ((num%10) != y)
                    return false;
                num -= (y * tenPow);
                num /= 10;
                tenPow /= 100;
            }
            
            return true;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.