c++


  • 0
     class Solution {
     public:
     bool isPalindrome(int x) {
        if( x < 0) return false;
        if( x / 10  == 0) return true;
        int base = 1;
        while(x/base >= 10){
            base = base*10;
        }
        
        while(x > 0){
            int right = x%10;
            int left = x/base;
            if(right != left) return false;
            x = (x - left*base)/10;
            base /= 100;
        }
        return true;
    }
    };

Log in to reply
 

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