*Shrug* this seems to work (Java, 258ms)


  • 0
    C

    I mean, they say "It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one." And then they don't give you any requirements or specify where to find them? In the real world, if you expect everyone to strictly adhere to their requirements, but then don't give them any.... you're going to end up with code like this:

    public static boolean isNumber(final String s) {
        if (s.contains("f")) {
            return false;
        }
        if (s.contains("D")) {
            return false;
        }
    
        try {
            Double.parseDouble(s);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }

  • 0

    This is exactly what I thought when I read the question. However, as exception is very costly, I'd try to gather more requirements.


Log in to reply
 

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