class Solution { public boolean isNumber(String s) { s = s.trim(); int n = s.length(); char[] arr = s.toCharArray(); boolean numSeen = false, dotSeen = false, eSeen = false; for(int i = 0; i < n; i++) { if(arr[i] >= '0' && arr[i] <= '9') numSeen = true; else if (arr[i] == '.') { if(eSeen || dotSeen) return false; dotSeen = true; } else if (arr[i] == 'e' || arr[i] == 'E') { if(!numSeen || eSeen) return false; numSeen = false; eSeen = true; } else if (arr[i] == '-' || arr[i] == '+') { if(i != 0 && arr[i-1] != 'e' && arr[i-1] != 'E') return false; } else { return false; } } return numSeen; } }