LeetCode-Feedback / LeetCode-Feedback

665 stars 318 forks source link

Missing Test Case - 65. Valid Number #24233

Open Zortexxx619 opened 1 week ago

Zortexxx619 commented 1 week ago

LeetCode Username

Zortexxx619

Problem Number, Title, and Link

  1. Valid Number https://leetcode.com/problems/valid-number/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

When using the C++ standard library, std::from_chars can easily be used to convert the string to a float and solve this problem, so long as:

Notably, from_chars also supports automatically detecting and converting strings of hexadecimal numbers, as long as they start with "0x" or "0X". There are, however, no testcases which start with those and are also valid hexadecimal strings, meaning the problem can be solved this way without accounting for these false positives.

Language Used for Code

C++

Code used for Submit/Run operation

class Solution {
public:
    bool isNumber(string s) {
        float f = 0;
        char* first = s.data() + sizeof(char) * (s[0] == '+');
        char* last  = s.data() + sizeof(char) * s.length();
        if (first == last) return false;
        auto [p, e] = from_chars(first, last, f);
        return (p == last && isfinite(f));
    }
};

Expected behavior

Given this code, a testcase such as "0x3b" (a hexadecimal number prepended with "0x" or "0X", valid in its entirety as far as from_chars is concerned) would return true, whereas it should expect false given the rules laid out in the problem description. No testcases like that exist, so the solution is accepted.

A single added testcase can fix this issue, without impacting solutions that opt to write parsers from scratch.

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 1 week ago

LeetCode Support commented: Hello,

Thank you for contributing to LeetCode and submitting a missing test case. Upon review, we found that your provided test case did not cause your solution code to fail and it was Accepted as before. This indicates that your test case may not address the specific edge case or scenario needed to highlight the issue in your solution.

Here are the test cases you submitted:

Test case #1:

"0x3b"

We encourage you to review your code and consider other potential edge cases that might reveal the underlying problem. If you identify any additional test cases or have further questions, please feel free to reply to this message or open a new issue with us.

We appreciate your engagement and efforts in helping us enhance our platform.

Best regards, LeetCode Support Team

Zortexxx619 commented 1 week ago

Hello there! I'm not sure I understand what you mean. The testcase being accepted by my solution is in fact true, I'm not arguing that. I'm saying it shouldn't be accepted per the details of the problem description.

exalate-issue-sync[bot] commented 6 days ago

LeetCode Support commented: Hello Zortexxx619,

Thank you for bringing this to our attention. We understand there may be some confusion regarding the behavior of hexadecimal numbers like "0x3b" within the context of this problem. To ensure that we fully understand and address the issue, could you provide additional clarity or examples demonstrating where the current problem constraints might be insufficient or misaligned with what should be expected? Your detailed insight will help us determine if there’s indeed a missing test case or if there's another aspect to consider.

We value your input and are here to assist you in aligning your solutions with problem expectations. Feel free to share any further details or ask additional questions.

Warm regards,

LeetCode Support Team