2
Max Possible combination of characters in the string has followig parts(stages)4
+/- number . number e/E +/- number7
Now check each characters at there correct stages or not and increament the8
stage as per the character found at ith position.14
bool isNumber(string s) {16
for (int i = 0; i < s.size(); ++i) {17
if ((s[i] == '+' || s[i] == '-') && (stage == 0 || stage == 5)) {19
} else if ((s[i] == 'e' || s[i] == 'E') && stage > 1 && stage < 5) {21
} else if (s[i] == '.' && stage < 3) {22
// both side of '.' do not have any digit then return false23
if (stage <= 1 && (i + 1 >= s.size() || !(s[i + 1] >= '0' && s[i + 1] <= '9')))26
} else if (s[i] >= '0' && s[i] <= '9') {27
if (!(stage == 2 || stage == 4 || stage == 7)) stage++;28
if (stage == 1 || stage == 6) stage++;32
if (stage <= 1 || stage == 5 || stage == 6) return false;