Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Valid Number

XPChallenge Points: 30
levelLevel: Hard

Given a string s, determine whether it represents a valid number.

A valid number can be:

 

  Integer: Digits with an optional + or - sign.

Example: "-5", "+12", "0".

 

  Decimal: Digits with a decimal point, with an optional + or - sign.

Examples: "3.14", "4.", ".9".

 

  Scientific Notation: An integer or decimal followed by e or E and then an integer (the exponent).

Examples: "2e10", "-1.5E-3".

 

Invalid numbers include strings with letters in the wrong place, multiple signs, or malformed exponents.

Example 1:

Input: s = "7.5"

Output: true

Explanation:

It’s a valid decimal number.

Example 2:

Input: s = "-3E8"

Output: true

Explanation:

It’s a valid scientific notation number.

Example 3:

Input: s = "12e"

Output: false

Explanation:

The exponent is incomplete.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result