Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98b0580

Browse files
committed
test git again add valid number
1 parent1cae143 commit98b0580

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

‎Hard/65-validNumber.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*@param {string} s
3+
*@return {boolean}
4+
*/
5+
// 1. if it is a '.', there was no . or e
6+
// 2. if it is a 'e', there was no e and the e is right after a number
7+
// 3. if it is a '+' or '-', it only can be at the begining or after e.
8+
varisNumber=function(s){
9+
varnumberSeen=false,
10+
dotSeen=false,
11+
eSeen=false,
12+
afterE=true,
13+
i;
14+
s=s.trim()
15+
16+
for(i=0;i<s.length;i++){
17+
if(parseInt(s[i])>=0&&parseInt(s[i])<=9){
18+
numberSeen=true;
19+
afterE=true;
20+
}elseif(s[i]==='.'){
21+
if(dotSeen||eSeen){
22+
returnfalse;
23+
}
24+
dotSeen=true;
25+
}elseif(s[i]==='e'){
26+
if(eSeen||!numberSeen){
27+
returnfalse;
28+
}
29+
eSeen=true;
30+
afterE=false;
31+
}elseif(s[i]==='+'||s[i]==='-'){
32+
if(i!==0||!eSeen){
33+
returnfalse
34+
}
35+
}else{
36+
returnfalse;
37+
}
38+
}
39+
40+
returnnumberSeen&&afterE;
41+
};

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
*[45. Jump Game II](https://leetcode.com/problems/jump-game-ii/) -[Solution](./Hard/45-jumpGameII.js)
197197
*[56. Merge Intervals](https://leetcode.com/problems/merge-intervals/) -[Solution](./Hard/56-MergeIntervals.js)
198198
*[57. Insert Interval](https://leetcode.com/problems/insert-interval/) -[Solution](./Hard/57-insertInterval.js)
199+
*[65. Valid Number](https://leetcode.com/problems/valid-number/) -[Solution](./Hard/65-validNumber.js)
199200
*[115. Distinct Subsequences](https://leetcode.com/problems/distinct-subsequences/) -[Solution](./Hard/115-distinctSubsequences.js)
200201
*[117. Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/) -[Solution](./Hard/117-populatingNextRightII.js)
201202
*[123. Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/) -[Solution](./Hard/123-bestTimeBuySellStockIII.js)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp