参考后
class Solution {
public:
bool isNumber(string s) {
size_t n = s.size();
size_t i = 0;
int nnum = 0;
int npoint = 0;
while (isspace(s[i]))
++i;
if (s[i] == '-' || s[i] == '+')
++i;
while (i != n) {
if (isdigit(s[i])) {
++nnum;
++i;
} else if (s[i] == '.') {
++npoint;
++i;
} else
break;
}
if (nnum <=0 || npoint > 1) return false;
if (i != n && s[i] == 'e') {
++i;
nnum = 0;
npoint = 0;
if (s[i] == '-' || s[i] == '+')
++i;
while (i != n) {
if (isdigit(s[i])) {
++nnum;
++i;
} else
break;
}
if (nnum <=0) return false;
}
while(i != n && isspace(s[i]))
++i;
return i == n;
}
};