int reverse(int x) {
if(x==0)
return 0;
int y = abs(x);
long long result = 0;
while(y > 0) {
result *= 10;
result += y % 10;
y /= 10;
}
if(result > INT_MAX || result < INT_MIN)
return 0;
if(x<0) {
return -result;
}
return result;
}
How is this code valid? It's clear that result is a long long variable but the return type of the code is int. The code still works.
Aucun commentaire:
Enregistrer un commentaire