Skip to content

Miss Test Case - 7. 整数反转 #30994

@by22Jy

Description

@by22Jy

LeetCode 用户名

_by2022Jy

问题号码、标题和链接

https://leetcode.cn/problems/reverse-integer/description/

Bug Category

缺少测试用例 (由于缺少测试用例而接受不正确/低效的代码)

描述

没有卡32位最大值和最小值的边界条件

你使用的语言

Java

你提交或者运行的代码

class Solution {
    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int num = x % 10;
            x /= 10;
            
            if (res > Integer.MAX_VALUE / 10 || res == Integer.MAX_VALUE / 10 && num > 5) {
                return 0;
            }

            if (res < Integer.MIN_VALUE / 10 || res == Integer.MIN_VALUE / 10 && num > 8) {
                return 0;
            }

            res = res * 10 + num;
        }

        return res;
    }
}

期望行为

对于正树边界值的情况应该考虑最后一位大于7
对于负数边界值的情况应该考虑最后一位小于-8

屏幕截图

No response

额外的上下文

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions