标签:style blog color io div 问题 sp log on
问题描述:
反转整数,例子:
输入:x = 123, return 321; x = -123, return -321
方法:
class Solution { public: int reverse(int x) { int newX = 0; int sign = 1; int tempX = 0; if(x == 0) newX = 0; // 处理负数 if(x < 0){ sign = -1; x = sign * x; } while(x != 0){ tempX = x % 10; newX = newX * 10 + tempX; x /= 10; } return sign * newX; } };
标签:style blog color io div 问题 sp log on
原文地址:http://www.cnblogs.com/cloudfeng/p/3957268.html