Solution in C


  • 1
    N
    int reverse(int x) {
        int digit;
        long rnum = 0;
        int n = x;
        
        while(n != 0)
        {
            digit = n % 10;
            rnum = rnum*10 + digit;
            n = n/10;
           
      // Checking the overflow
            if((rnum > INT_MAX) || (rnum < INT_MIN))
                return 0;
        }       
        return rnum;
    }
    

  • 0
    C

    not at all compiling ..needed lot of correction


Log in to reply
 

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