Reverse digits of an integer(C)


  • 0
    P
    typedef int INT32;         // -0x7fffffff ~ 0x7fffffff
    typedef long long INT64;
    
    INT32 reverse(INT32 x) {
        INT64 lValue = 0;
        while(x != 0)
        {
            lValue = lValue*10 + x % 10;
            x = x/10;
            if((lValue > 0x7fffffff) || (lValue < -0x7fffffff))
                return 0;
        }
        return lValue;
    }

Log in to reply
 

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