rev
as 0 to store the reversed number.x
is not 0:
a. Perform the pop operation: pop = x % 10
and x /= 10
.
b. Check for overflow: if rev > INT_MAX/10
or rev < INT_MIN/10
, return 0.
c. If rev
is at the boundary of overflow, check the last digit: if rev == INT_MAX/10
and pop > 7
, or if rev == INT_MIN/10
and pop < -8
, return 0.
d. Perform the push operation: rev = rev * 10 + pop
.rev
.