Validate if a given string is numeric.
Some examples:"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
就看能不能将各种情况都考虑周到了。
1 class Solution { 2 public: 3 bool isNumber(const char *s) { 4 while (*s == ' ') ++s; 5 while (*s == '+' || *s == '-') ++s; 6 bool exp = false, space = false, point = false; 7 bool number = false; 8 while (*s != '