首页 > 其他 > 详细

LeetCode #7 Reverse Integer

时间:2017-01-19 04:46:39      阅读:249      评论:0      收藏:0      [点我收藏+]

题目链接

题目大意:根据输入的数值,将其各位反转后输出,若越界(上界或者下界)时,输出0;

 

 1 class Solution {
 2 public:
 3     int reverse(int x) {
 4       const int maxint = 0x7fffffff;
 5       const int minint = 0x80000000;
 6       long long ans = 0;
 7       while( x != 0 )
 8       {
 9           ans = ans * 10 + (x % 10);
10           x /= 10;
11       }
12       if ( ans > maxint || ans < minint )
13         ans = 0 ;
14     return ans ;
15     }
16 };

 

LeetCode #7 Reverse Integer

原文:http://www.cnblogs.com/pang-zp/p/6298699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!