-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path65.cpp
More file actions
32 lines (32 loc) · 838 Bytes
/
65.cpp
File metadata and controls
32 lines (32 loc) · 838 Bytes
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
class Solution {
public:
bool isNumber(string s) {
if(s.length() == 0)
return false;
int i = 0,n = s.length()-1;
bool e = false, dot = false, digit = false;
while(i <= n && s[i] == ' ')
i++;
while(n>= i && s[n] == ' ')
n--;
if(s[i] == '+' || s[i] == '-')
i++;
if(i > n)
return false;
for(;i <= n;i++){
if(isdigit(s[i])){
digit = true;
continue;
}
else if(s[i] == 'e' && digit && i != n && !e){
e = true;
if(s[i + 1] == '+' || s[i + 1] == '-')
if(i == n - 1) return false;
else i++;
}
else if(s[i] == '.' && !dot && !e) dot = true;
else return false;
}
return digit;
}
};