Nothing To See Here (C++)


  • 0
    F
    class Solution {
    public:
        int reverse(int x) {
            bool isNeg = x < 0;
            x = abs(x);
            long ans = 0;
            while(x > 0){
                ans *= 10;
                ans += x%10;
                x/=10;
            }
            if(ans > INT_MAX){
                return 0;
            }
            return isNeg ? 0-(int)ans : (int)ans;
        }
    };
    

Log in to reply
 

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