32 BIT interger


#1

use this

you have to use long long int because to stote large number because it is possible when we reverse this number so number less than interger range

int Solution::reverse(int A) {

long long int i,j,k=0,y,c=0;

if(A<0)
{
    k=1;
    A=-A;
}

while(A>0)
{
    int r=A%10;
    c=c*10+r;
    A=A/10;
}
if(k==1)
c=-c;

if(-2147483648 > c)
return 0;

if(2147483647 < c)
return 0;



return c;

}


#2

You can not compare value to its MAX_VALUE because when a integer exceeds its MAX_VALUE it just complete one cycle and starts from MIN_VALUE.


#3

A : -1146467285

Your function returned the following :

-1532679115

The expected returned value :

0
not working for this input


#4

instead of comparing at the last compare at each step while taking the reverse ie.(in while loop check for c<INT_MAX)