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

Commit 529113a

Browse files
solved: Valid Number
1 parent bf82119 commit 529113a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,14 @@ void place(
505505
board[i][j] = '.';
506506
}
507507
}
508+
```
509+
510+
### Valid number
511+
512+
```dart
513+
bool isNumber(String s) {
514+
if (s == "Infinity" || s == "-Infinity" || s == "+Infinity") return false;
515+
516+
return num.tryParse(s) != null;
517+
}
508518
```

‎src/valid_number.dart‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
void main(List<String> args) {
2+
List<String> cases = [
3+
"2",
4+
"0089",
5+
"-0.1",
6+
"+3.14",
7+
"4.",
8+
"-.9",
9+
"2e10",
10+
"-90E3",
11+
"3e+7",
12+
"+6e-1",
13+
"53.5e93",
14+
"-123.456e789",
15+
];
16+
17+
for (final testcase in cases) {
18+
print(isNumber(testcase));
19+
}
20+
}
21+
22+
bool isNumber(String s) {
23+
if (s == "Infinity" || s == "-Infinity" || s == "+Infinity") return false;
24+
25+
return num.tryParse(s) != null;
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /