7. Reverse Integer

来源:互联网 发布:淘宝女装美工 编辑:程序博客网 时间:2024/06/07 19:08
public class Solution {    public int reverse(int x) {        long ans = 0;        while(x != 0){            ans = ans * 10 + x%10;            x = x /10;        }        if( ans < Integer.MIN_VALUE || ans > Integer.MAX_VALUE){            return 0;        }        return (int)ans;            }}


注意:

1.leetcode上若用包装类型会报错,即上面的long换成Long,int换成Integer

原创粉丝点击