标签:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
题意:将数字反转
思路:注意要判断溢出就是了
class Solution { public: int reverse(int x) { long long ans = 0; while (x) { ans = ans * 10 + (x % 10); x /= 10; } if (ans > INT_MAX) ans = 0; if (ans < INT_MIN) ans = 0; return ans; } };
标签:
原文地址:http://blog.csdn.net/u011345136/article/details/42487337