LeetCode——整数反转

题目地址:https://leetcode-cn.com/problems/reverse-integer/

解题思路:注意题目给的“32 位的有符号整数”信息。我们在反转计算的过程中,可能会溢出。题目的范围是[-2^31,2^31]。

int reverse(int x) {
    long returnS = 0;
    while (x) {
        if (returnS * 10 > (long)pow(2.0, 31) || returnS * 10 < -(long)pow(2.0, 31))
            return 0;
        returnS = returnS * 10 + (x % 10);
        x /= 10;
    }
    return returnS;
}
原文地址:https://www.cnblogs.com/cc-xiao5/p/13268396.html