Failed output for 123 but passes for large values like 2147447412

interview-questions
Tags: #<Tag:0x00007f2428b3e630>

#1

my code is as below. It works for various large inputs but returns 321 specially for 123 as input. help please.

int Solution::isPalindrome(int A)

{
int mirror=0;
int original=A;
if(A<0)
{
return 0;
}

else 
{
    while(A!=0)
    {
    mirror=mirror*10+A%10;
    A/=10;
    }
    
    if(mirror==original)
    {
        return  1;
        
    }
}

}


#2

Hi, make sure to return 0 if mirror is not equal to original, you’re missing a return statement.