果果1020

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

Reverse digits of an integer.

 1 public class Solution {
 2     public int reverse(int x) {
 3         
 4         long lx = x;
 5         long nx = 0;
 6         while (lx != 0) {
 7             nx = nx * 10 + lx % 10;
 8             lx /= 10;
 9         }
10         
11         return (int)((nx > Integer.MAX_VALUE || nx < Integer.MIN_VALUE) ? 0 : nx);
12     }
13 }

 

posted on 2017-01-02 12:29  果果1020  阅读(104)  评论(0)    收藏  举报