Valid Number
A valid number can be split into the following components:
• An integer followed by an optional exponent.
• A decimal number followed by an optional exponent.
An integer can have:
- An optional '+' or '-' sign.
- One or more digits.
A decimal number can have:
- An optional '+' or '-' sign.
- Digits before the decimal point, digits after the decimal point, or both.
- At least one digit somewhere in the number.
An exponent consists of:
- The character 'e' or 'E'.
- An optional '+' or '-' sign.
- One or more digits.
Given a string s, return true if it represents a valid number. Otherwise, return false.
Example 1
Input
2
Output
true
Explanation
The string "2" is a valid integer, so it represents a valid number.
Example 2
Input
0089
Output
true
Explanation
Leading zeros are allowed in a valid integer.
Constraints
Hints:
Hint 1
Process the string character by character while tracking whether you have seen digits, a decimal point, or an exponent.
Hint 2
A sign is allowed only at the beginning of the number or immediately after an exponent. Ensure that at least one digit exists before returning true.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 4, 2026
Last updated
Aug 5, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output