import java.util.*;
public class Solution {
public boolean isNumeric (String str) {
str = str.trim();
if(str.length() == 0){
return false;
}
if(isDecimal(str,0,str.length()-1) || isInteger(str,0,str.length()-1) || isScientific(str)){
return true;
}
return false;
}
public boolean isDecimal(String str,int left,int right){
int num = 0;
for(int i = left;i<=right;i++){
if(str.charAt(i) == '+' || str.charAt(i)=='-'){
if(i==left && i<right){
continue;
}else{
return false;
}
}
if(str.charAt(i) == '.'){
num++;
if(num == 2){
return false;
}
if(i>left && i<right && Character.isDigit(str.charAt(i-1)) && Character.isDigit(str.charAt(i+1))){
continue;
}else if(i>left && Character.isDigit(str.charAt(i-1))){
continue;
}else if(i<right && Character.isDigit(str.charAt(i+1))){
continue;
}else{
return false;
}
}
if(!Character.isDigit(str.charAt(i))){
return false;
}
}
if(num == 1){
return true;
}else{
return false;
}
}
public boolean isInteger(String str,int left,int right){
for(int i = left;i<=right;i++){
if(str.charAt(i)=='+' || str.charAt(i) == '-'){
if(i == left && i<right){
continue;
}else{
return false;
}
}
if( !Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
public boolean isScientific(String str){
int index = 0;
for(int i = 0;i<str.length();i++){
if(str.charAt(i) == 'e' || str.charAt(i) == 'E'){
index = i;
break;
}
}
if(index == 0 || index == str.length()-1){
return false;
}
if((isDecimal(str,0,index-1) || isInteger(str,0,index-1)) && isInteger(str,index+1,str.length()-1)){
return true;
}
return false;
}
}