Solution to reverse integer in C


  • 0
    V

    Re: Solution in C

    int reverse(int x) {
    int num=x;
    int unit,sum=0;
    while(num!=0) {
    unit = num%10;
    sum=sum*10 + unit;
    if (sum-((sum/10)*10) != unit) {
    return 0;
    } else {
    num=num/10;
    }
    }
    return sum;
    }


Log in to reply
 

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