It does work in cplusplus


  • 0
    J

    Hey, everyone, I did it like this in cplusplus, and it worked

    class Solution {
    public:
        int reverse(int x) {
            long result = 0;
            while (x != 0)
            {
                result = result*10 + x%10;
                x /= 10;
            }
            if (x < 0) result *= -1;
            return (int)(result < INT_MIN || result > INT_MAX)?0:result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.