-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path65.cpp
36 lines (36 loc) · 875 Bytes
/
65.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// simple.cpp
class Solution {
public:
bool isNumber(string s) {
s.erase(0, s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
bool eFlag = false, dotFlag = false, signFlag = false, digitFlag = false;
for (auto c : s) {
if (c >= '0' && c <= '9') {
digitFlag = true;
} else
switch (c) {
case '+':
case '-':
if (signFlag || digitFlag || dotFlag)
return false;
signFlag = true;
break;
case 'e':
if (eFlag || !digitFlag)
return false;
eFlag = true;
signFlag = digitFlag = dotFlag = false;
break;
case '.':
if (dotFlag || eFlag)
return false;
dotFlag = true;
break;
default:
return false;
}
}
return digitFlag;
}
};