image.png

    1. class Solution {
    2. public:
    3. int reverse(int x) {
    4. long n = 0;
    5. while (x)
    6. {
    7. n = n * 10 + x % 10;
    8. x /= 10;
    9. }
    10. return n > INT_MAX || n < INT_MIN ? 0 : n;
    11. }
    12. };