c++ solution with two pointers


  • 2
    D
    class Solution {
    public:
        bool isPalindrome(int x) {
            
            if (x < 0) return false;
            
            int half = 0;
            int fast = x;
            
            while(fast)
            {
                half = half * 10 + x%10;
                x = x/10;
                fast /= 100;
            }
            
            if(x == half || x == half/10) return true;
            else return false;
            
               }
    };
    

Log in to reply
 

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