My c++ answer, top 18.74%


  • 0
    S
    bool isPalindrome(int x) {
        
         if (x<0 || (x!=0 && x%10==0))return false;  //last digit is 0, false
         if (x<10 && x>0) return true; // 0-9, true
        
         int left =0,right=x,mod=0;    
    
         while (x>left && x>=10){
             mod = x%10;
             left=left*10+mod;
             right=x;
             x=x/10;
         }
    
         if(left==right || left==x)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.