Valid Number
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.
其他测试用例:
" " false
"3." true
"e" false
"." false
"3. " true
"46.e3" true
" 005047e+6" true
"6+1" false
1.符号 后面只能跟 数字,点
2.点 后面只能跟 数字,空格,指数e
3.指数 后面只能跟 数字,符号
4.空格只能位于开头或结尾,去除开头的空格后,空格后面只能接空格(必须位于末尾)
5.去除开头的符号后,符号只能位于指数e之后,且只能出现一次
6.点只能出现一次,且不能位于指数之后
7.指数只能出现一次,且前面需要有数字
8.符号,指数,单独的点,不能做结尾
1 class Solution { 2 public: 3 4 enum TYPE 5 { 6 INVALID, 7 SPACE, 8 SIGN, 9 DIGIT, 10 DOT, 11 EXP 12 }; 13 14 bool isNumber(const char *s) { 15 16 while(*s!='