How do I judge multiplication overflow?


  • 0
    M

    I don't how to do it. so I using long long save resualt, and at end I convert it to int and compare it,do you have any way else? thanks.
    class Solution {
    public:
    int reverse(int x) {
    long long int ret=0;
    do
    {
    ret*=10;
    ret+=x%10;
    }
    while(x/=10);
    return ret==int(ret)?ret:0;
    }
    };


Log in to reply
 

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