首页 > 其他 > 详细

Reverse Integer

时间:2014-11-09 22:02:00      阅读:169      评论:0      收藏:0      [点我收藏+]

Reverse Integer

Reverse digits of an integer.

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

 1 public class Solution {
 2     public int reverse(int x) {
 3         int result = 0;
 4         boolean flag_neg = false;
 5         if(x < 0){
 6             flag_neg = true;
 7             x = -x;
 8         }
 9         while(x != 0){
10             int temp = x % 10;
11             result = result * 10 + temp;
12             x /= 10;
13         }
14         if(flag_neg)
15             result = -result;
16         return result;
17     
18     }
19 }

 

Reverse Integer

原文:http://www.cnblogs.com/luckygxf/p/4085921.html

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