class Solution { public boolean isNumber(String s) { s=s.trim(); int idx=s.indexOf('e'); if(idx>0) return isNum(s.substring(0,idx), false)&&isNum(s.substring(idx+1), true); return isNum(s, false); } private boolean isNum(String s, boolean dot){ if(s.length()==0) return false; int numlen=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)>='0'&&s.charAt(i)<='9') numlen++; else if(i==0&&(s.charAt(i)=='+'||s.charAt(i)=='-')) continue; else if(s.charAt(i)=='.'&&dot==false) dot=true; else return false; } return numlen>0; } }