Reverse a integer in java


  • 0
    P

    public int reverse(int x) {
    int reverse_num = 0;
    while(x != 0){
    reverse_num = reverse_num * 10 + x % 10;
    x = x / 10;
    }
    return reverse_num;
    }


Log in to reply
 

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