FunctionRacerProblemsRace

Is It a Number

HardStringsPython, JavaScript, TypeScript, Java, C++

Return True if s is a number written like this, and nothing more:

1. an optional + or -,
2. digits with at most one dot, and at least one digit before or after the dot (7, 7., .5, 3.14),
3. optionally an exponent: e or E, an optional + or -, then at least one digit.

So "-12.5e+3" and ".5" are numbers, while "e9", "1e", ".", "1 " and "inf" are not.

Example 1

s "-12.5e+3"
returns true

A sign, digits with a dot, then an exponent with its own sign and digits.

Example 2

s "1e"
returns false

An exponent needs at least one digit after the e.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems