My 8ms c++ simple solution


  • 0
    S
    class Solution {
    public:
        int reverse(int x) {
            long long ret = 0;
            while (x) {
                int data = x % 10;
                ret = ret * 10 + data;
                if (ret > numeric_limits<int>::max() || ret <= numeric_limits<int>::min()) {
                    ret = 0;
                    break;
                }
                x /= 10;
            }
    
            return ret;
        }
    };

Log in to reply
 

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