题解 | #反转数字#

反转数字

http://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a

import java.util.*;


public class Solution {
    /**
     * 
     * @param x int整型 
     * @return int整型
     */
    public int reverse (int x) {
        // write code here
        long res = 0;

        while (x != 0) {
            res *= 10;
            res += x %10;
            x /= 10;
        }

        return res > Math.pow(2, 31) - 1 || res < -Math.pow(2, 31) ? 0 : (int) res;
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务