题解 | #反转数字#

反转数字

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

代码直接抄的,简洁明了。

import java.util.*;

public class Solution {
  
    public int reverse (int x) {
        long n=0;
        while (x!=0){
            n = n*10+x%10;
            x = x/10;
        }
		//三元表达式并强转
      	//这里强制转换会把超出范围的数排除在外
        return (int)n==n?(int)n:0;
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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