Valid Number

Hard

Topics
String

Given a string s, return true if s is a valid number. A valid number has an optional sign, an integer or decimal part with at least one digit, and an optional exponent (e or E) followed by an optional sign and at least one digit.

Example 1

Input:  s = "0"
Output: true

Example 2

Input:  s = "e"
Output: false

Example 3

Input:  s = "-90E3"
Output: true

Constraints

  • 1 <= s.length <= 12
  • s consists of digits, '+', '-', '.', 'e', 'E'.
Run ⌘' · Submit ⌘⏎