Valid Number algo (using c++ regex) timing out.

  • 0

    Hello, my first post. My algorithm to verify if a string input is a valid number is timing out while submitting my solution. It times out at different test cases. I'm using very simple regex matching logic. Not sure if the timeout is set to be too narrow. Dont think the algo is slow (or as slow/efficient as the c++ regex implementation). Core logic is below. Other than that, there is some white-space stripping logic.

            std::vector<std::regex> regExs;
            // Handle case where: +1.1e-2, etc
            // Handle case where +3.e1
            // Handle case where +.1e1 or .1 or .1e-1
            for(auto regEx : regExs) {
                if(std::regex_match(s, regEx))
                    return true;
            return false;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.