码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode #7] Reverse integer

时间:2016-10-01 12:47:12      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

 1 // refer to http://bangbingsyb.blogspot.com/search?q=Reverse+Integer
 2 class Solution {
 3 public:
 4     int reverse(int x) {
 5         int ret = 0;
 6         while (x != 0) {
 7         // handle overflow/underflow
 8             if (abs(ret) > 214748364) return 0;
 9             ret = ret * 10 + x % 10;
10             x /= 10;
11         }
12         return ret;
13     }
14 };

 

[LeetCode #7] Reverse integer

标签:

原文地址:http://www.cnblogs.com/amadis/p/5925638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!