classSolution(object):defisNumber(self,s):""" :type s: str :rtype: bool """##### transitionTable[state][inputtype] = value##### state: 0==invalid, 1==space, 2==sign, 3==digit, 4==dot, 5==exponent, 6==num_inputs# inputtype: 如下INVALID=0;SPACE=1;SIGN=2;DIGIT=3;DOT=4;EXPONENT=5# value:# 0 no input or just spaces# 1 input is digits# 2 no digits in front just Dot# 3 sign# 4 digits and dot in front# 5 input e or E (exponent)# 6 after e input sign# 7 after e input digits# after valid input input spacestate=0;i=0whilei<len(s):inputtype=INVALIDifs[i]==' ':inputtype=SPACEelifs[i]=='-'ors[i]=='+':inputtype=SIGNelifs[i]in'0123456789':inputtype=DIGITelifs[i]=='.':inputtype=DOTelifs[i]=='e'ors[i]=='E':inputtype=EXPONENTstate=transitionTable[state][inputtype]ifstate==-1:returnFalseelse:i+=1returnstate==1orstate==4orstate==7orstate==8