Easy to understand cpp


#1

int Solution::reverse(int A)
{
vector temp;
int count=0;
while(A!=0)
{
temp.push_back(A%10);
A/=10;
count++;
}
if(temp.size()>10) return 0;
long long ret=0, div=1;
for(int i=temp.size()-1; i>=0; i–)
{
ret+=divtemp[i];
div
=10;
}
if(ret>=-2147483648&&ret<=2147483647) return ret;
else return 0;
}


#2

Why and how is it working for negative numbers? For eg, (-123 % 10) should give 7, which is not what we want.