This is a valid string?


  • 0
    H

    tried to get a regex solution but found it is so frustrated.
    Input: "46.e3"
    Output: false
    Expected: true


  • 0
    L

    enum STATUS{
    Blank=0,
    Signal=1,
    Number=2,
    Dot=3,
    ZiMue=4,
    Alph=5,
    End=6,
    T=98,
    F=99
    };

    STATUS getstatus(char c){
    if(c==' ')return Blank;
    else if(c=='+'||c=='-')return Signal;
    else if(c>='0'&&c<='9')return Number;
    else if(c=='.')return Dot;
    else if(c=='e')return ZiMue;
    else if (c=='\0')return End;
    else return Alph;
    }
    bool isNumber(string s) {
    int sTable[11][7]={ {1,2,3,4,F,F,F},
    {1,2,3,4,F,F,F}, //1
    {F,F,3,4,F,F,F}, //2
    {9,F,3,10,6,F,T},
    {F,F,5,F,F,F,F},
    {9,F,5,F,6,F,T},
    {F,7,8,F,F,F,F},
    {F,F,8,F,F,F,F},
    {9,F,8,F,F,F,T},
    {9,F,F,F,F,F,T},
    {9,F,5,F,6,F,T}
    };

    int status=sTable[0][getstatus(s[0])];
    int k=1;
    while(status!=(int)T&&status!=(int)F)
    {      
    //cout<<c<<endl;
    status=sTable[status][getstatus(s[k++])];		
    }			
    if(status==T) return true;
    else return false;}
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.