8ms c++ accepted solution


  • 3
    W
        long int res=0;
        int i;
    
        while(x){
            res = res*10+x%10;
            x = x/10;
        }
        if(abs(res)>pow(2,31))
            return 0;
        return res;

  • 0
    D

    strange. this can't be right. it already overflowed by the time it was tested.
    UPDATE: sorry, you were right. realized you used long int.


Log in to reply
 

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