标签:style blog color io div sp log on c
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
思路:
1 class Solution { 2 public: 3 int reverse( int x ) { 4 double val = 0.0; 5 while( x != 0 ) { 6 val = 10 * val + x % 10; 7 x /= 10; 8 } 9 if( val > INT_MAX || val < INT_MIN ) { return -1; } 10 return (int)val; 11 } 12 };
标签:style blog color io div sp log on c
原文地址:http://www.cnblogs.com/moderate-fish/p/3960708.html