标签:
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; } };
标签:
原文地址:http://www.cnblogs.com/xiaoying1245970347/p/4581572.html