leetcode valid number
细节很多,不是很容易做对
class Solution { public: bool isNumber(const char *s) { bool flag; while(*s==' ') s++; const char *s2=s+strlen(s)-1; while(*s2==' ') { s2--; } if(*s=='+'||*s=='-')s++; const char *s1=s; int point=0; int e=0; int count=0; while(*s1!='\0'&&s1<=s2) { if(isdigit(*s1)){s1++;count++;} else if(*s1=='.'&&e==0){s1++;point++;} else if(*s1=='e'&&s1!=s&&count>=1) { if(isdigit(*(s1+1))) {s1=s1+2;e++;} else if((s1+2<=s2)&&(*(s1+1)=='+'||*(s1+1)=='-')) {s1=s1+2;e++;} else return false; } else return false; } if(point<=1&&e<=1&&count>=1)return true; else return false; return true; } };