C++ Solution


  • 0
    T

    The best way to solve this question without using extra space is by reversing the number and checking if they are equal.
    Cases with least significant digit being '0' need not be checked and can be eliminated first.

    bool check_palindrome(int num){
       //removing edge cases
       if(num<0 || (num!=0 && num%10==0))
               return false;
       int rev_num=0;
       int temp=num;
       while(temp!=0){
              rev_num=rev_num*10+(temp%10);
              temp=temp/10;
       }
       if(num==rev_num)
             return true;
       return false;
    }
    

Log in to reply
 

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