My Concise and Clean C++ Code


  • 0
    T
    class Solution {
    public:
        int reverse(int x) {
            long r = 0;
            while (x) {
                int remainder = x % 10;
                r = r * 10 + remainder;
                x /= 10;
            }
            
            return (r >= INT_MIN && r <= INT_MAX) ? r : 0;
        }
    };
    

Log in to reply
 

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