C++_Accepted_18ms


  • 0
     class Solution {
     public:
     int reverse(int x) {
        if(x/10 == 0) return x;
        long sum = 0;
        while(x != 0){
            int tmp = x % 10;
            sum = sum * 10 + tmp;
            x /= 10;
        }
        
        if(sum > INT_MAX || sum < INT_MIN) return 0;
        return (int)sum;
    }
    };

Log in to reply
 

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