LeetCode刷题之旅(7)

来源:互联网 发布:it 网络 编辑:程序博客网 时间:2024/05/18 14:15

题目描述

注意溢出时的处理,坑爹的LeetCode,居然返回0,不应该是-1吗??

public class Solution {    public int reverse(int x) {        long res = 0;        while (x != 0) {            res = res * 10 + x % 10;            x /= 10;        }        if(res > Integer.MAX_VALUE || res < Integer.MIN_VALUE){            return 0;        }        return (int) res;    }}
0 0
原创粉丝点击