标签:反转 rev mamicode ima pre ever == solution code
在程序循环内终止更好。
class Solution { public: int reverse(int x) { int num = 0; while (x != 0) { int n = x % 10; x /= 10; //-2,147,483,648 ~ 2,147,483,647 if (num > INT_MAX/10 || (num == INT_MAX/10 && n > INT_MAX%10)) return 0; if (num < INT_MIN/10 || (num == INT_MIN/10 && n < INT_MIN%10)) return 0; num = num * 10 + n; } return num; } };
LeetCode 7. 整数反转 Reverse Integer
标签:反转 rev mamicode ima pre ever == solution code
原文地址:https://www.cnblogs.com/ZSY-blog/p/12946035.html