271. Valid Number

HardStringString

Given a string s, return true if s is a valid number. A valid number may have an optional sign, an integer or decimal part, and an optional exponent ('e'/'E' followed by an optional sign and an integer). Leading/trailing characters other than these make it invalid.

Input: A quoted string s.

Output: Boolean — true or false.

Examples

Example 1
Input: "0"
Output: true
Explanation: Integer.
Example 2
Input: "3.14"
Output: true
Explanation: Decimal.
Example 3
Input: "abc"
Output: false
Explanation: Not a number.

Constraints

Asked by

MetaAmazonBloombergGoogleMicrosoft
Solve this problem in the editor →