Basic 8ms C++ solution


  • 0
    D
    class Solution {
    public:
        int reverse(int x) {
            long long int result = 0;
            while (x) {
                result = 10 * result + x % 10;
                x = x / 10;
            }
            return result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min() ? 0 : result;
        }
    };

  • 0
    G

    I am not a C++ programmer, but could you explain this line?

    return result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min() ? 0 : result;
    

    tks


Log in to reply
 

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