reverse integer


  • 0
    S

    Given a 32-bit signed integer, reverse digits of an integer.

    Given a 32-bit signed integer, reverse digits of an integer.

    Given a 32-bit signed integer, reverse digits of an integer.

     int reverse(int x) {
            int j = 1;
            if(x < 0)  { j = -1; x = x * -1;}
            while(x > 0)
            {
    //this is needed for overflow
            if((int64_t)y * 10 >= 2147483647) 
            {
            return 0; 
            }
            y = y * 10;
            
            y = y + x % 10;
            printf("%d ",y);
            x = x / 10; 
            
            }
            
           
           
                return y * j; 
        }
    

Log in to reply
 

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