Reverse Integer in C


  • 0
    A

    int reverse(int A) {
    int temp = A;
    long rev = 0;

    while(A != 0)
    {
        rev *=10;
        rev += A%10;
        A /= 10;
    }
    if( rev > INT_MAX )
        return 0;
    if( rev < INT_MIN )
        return 0;
    return rev;
    

    }


Log in to reply
 

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