标签:logs max rem blog min style main solution pre
class Solution { public: int reverse(int x) { int ret = 0; int int_max_divide_10 = INT_MAX / 10; int int_max_mod_10 = INT_MAX % 10; int int_min_divide_10 = INT_MIN / 10; int int_min_mod_10 = INT_MIN % 10; while (x != 0){ int remainder = x % 10; if (x > 0 && (ret > int_max_divide_10 || (ret == int_max_divide_10 && remainder > int_max_mod_10)) || x < 0 && (ret < int_min_divide_10 || (ret == int_min_divide_10 && remainder < int_min_mod_10))) { return 0; } ret *= 10; ret += remainder; x /= 10; } return ret; } };
Leet code problem 7: reverse integer digit
标签:logs max rem blog min style main solution pre
原文地址:http://www.cnblogs.com/nosaferyao/p/7531907.html