LeetCode:Reverse Integer
problem:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
solution:逐个取数字; 处理溢出问题 (INT_MIN INT_MAX)
class Solution { public: int reverse(int x) { long result=0; while(x) { result=result*10+x%10; if(result<INT_MIN||result>INT_MAX) return 0; x=x/10; } return result; } };