Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit deb0cd1

Browse files
committedJan 5, 2025
Add solution #65
1 parent 96288de commit deb0cd1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
60|[Permutation Sequence](./0060-permutation-sequence.js)|Hard|
6969
62|[Unique Paths](./0062-unique-paths.js)|Medium|
7070
64|[Minimum Path Sum](./0064-minimum-path-sum.js)|Medium|
71+
65|[Valid Number](./0065-valid-number.js)|Hard|
7172
66|[Plus One](./0066-plus-one.js)|Easy|
7273
67|[Add Binary](./0067-add-binary.js)|Easy|
7374
69|[Sqrt(x)](./0069-sqrtx.js)|Medium|

‎solutions/0065-valid-number.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 65. Valid Number
3+
* https://leetcode.com/problems/valid-number/
4+
* Difficulty: Hard
5+
*
6+
* Given a string s, return whether s is a valid number.
7+
*
8+
* For example, all the following are valid numbers: "2", "0089", "-0.1", "+3.14", "4.", "-.9",
9+
* "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789", while the following are not
10+
* valid numbers: "abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53".
11+
*
12+
* Formally, a valid number is defined using one of the following definitions:
13+
* - An integer number followed by an optional exponent.
14+
* - A decimal number followed by an optional exponent.
15+
*
16+
* An integer number is defined with an optional sign '-' or '+' followed by digits.
17+
* A decimal number is defined with an optional sign '-' or '+' followed by one of the
18+
* following definitions:
19+
* - Digits followed by a dot '.'.
20+
* - Digits followed by a dot '.' followed by digits.
21+
* - A dot '.' followed by digits.
22+
* - An exponent is defined with an exponent notation 'e' or 'E' followed by an integer number.
23+
*
24+
* The digits are defined as one or more digits.
25+
*/
26+
27+
/**
28+
* @param {string} s
29+
* @return {boolean}
30+
*/
31+
var isNumber = function(s) {
32+
return s.trim().length && !isNaN(s.trim()) && !s.includes('Infinity');
33+
};

0 commit comments

Comments
 (0)
Please sign in to comment.