-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
31 lines (31 loc) · 1021 Bytes
/
Solution.java
File metadata and controls
31 lines (31 loc) · 1021 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
public class Solution {
public boolean isNumeric(char[] str) {
int len = str.length;
boolean hasDot = false;
for(int i = 0; i < len; i++){
if(str[i] == '+' || str[i] == '-'){
if((!hasDot || str[i-1] == 'e' || str[i-1] == 'E')
&& i + 1 < len && str[i+1] >= 0
&& str[i+1] <= 9){
continue;
}else{
return false;
}
}else if(str[i] == 'e' || str[i] == 'E'){
if(i + 1 < len && ((str[i+1] >= 0 && str[i+1] <= 9)
|| str[i+1] == '+' || str[i+1] == '-')){
continue;
}else{
return false;
}
}else if(str[i] == '.'){
if(!hasDot && i + 1 < len){
hasDot = true;
}else{
return false;
}
}
}
return true;
}
}