What wrong with my code


#1

int Solution::reverse(int A) {
bool sign =0;
if(A>=INT_MAX||A<=INT_MIN)
{
return 0;
}
if(A<0)
{
sign=1;
A=-A;
}
int digit = (int)log10(A);
int num = ((A%10)*pow(10,digit)+reverse(A/10));
if(num>INT_MAX)return 0;
if(sign)
{
return -num;
}
return num;
}

The code is showing memory limit exceeded when input is -1234567891, is it because of the recursive call?


#2

What if?
(int num = ((A%10)*pow(10,digit)+reverse(A/10)))
Sums up to be greater than INT_MAX?
You compare num>INT_MAX after storing numbers in num.