Java Solution for reverse integer


  • 0
    V

    public int reverse(int x)
    {
    int reverse = 0;

    while (x != 0)
    {
        int digit= x % 10;
        int newRev = reverse * 10 + digit;
        if ((newRev - digit) / 10 != result)
        {  return 0;
         }
        result = newResult;
        x = x / 10;
    }
    
    return result;
    

    }


Log in to reply
 

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