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

LeetCode : reverse integer

时间:2014-07-29 11:25:06      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   2014   art   

bubuko.com,布布扣

解法:

bubuko.com,布布扣
 1 class Solution {
 2 public:
 3     int reverse(int x) {
 4         int signal = (x>0)? 1:-1;   /* signal记录正负号 */
 5         x=abs(x);
 6         int tmp = 0;
 7 
 8         if(x == 0)
 9             return x;
10 
11         while(x)
12         {
13             tmp = tmp*10+x%10;
14             x = x/10;
15         }
16 
17         tmp = tmp*signal;      /* 乘上符号 */
18 
19         return tmp;
20     }
21 };
View Code

 

LeetCode : reverse integer,布布扣,bubuko.com

LeetCode : reverse integer

标签:style   blog   http   color   os   io   2014   art   

原文地址:http://www.cnblogs.com/crystal-miao/p/3874045.html

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