Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access