FunctionRacerProblemsRace

Valid Decimal Literal

MediumStringsPython, JavaScript, TypeScript, Java, C++

Return True if s is a valid decimal literal, otherwise False. A valid decimal literal is, in this order:

Nothing else may appear: no spaces, no second sign, no second dot and no other letters. For example -1.5e10, +.5, 3. and 0e0 are valid, while e5, 1e, 1.2.3, --1, 1 and the empty string are not.

Example 1

s "-1.5e10"
returns true

A sign, digits on both sides of the dot, and an exponent with digits.

Example 2

s "+.5"
returns true

The digits before the dot may be missing when there are digits after it.

Example 3

s "1e"
returns false

The exponent marker must be followed by at least one digit.

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