LeetCode 65. Valid Number

题目

+.9 也是合法数字吗

class Solution {
public:
    bool isNumber(string s) {
        
        int start=0;
        int sign=0;
        int sign2=0;
        int e=0;
        int point=0;
        int last=0;
        int number=0;
        int end=0;
        for(int i=0;i='0'&&s[i]<='9')))
                {
                    return false;
                }
                
                start=1;
                if(s[i]=='+'||s[i]=='-')
                {
                    sign=1;
                }
                else if(s[i]=='.')
                {
                    point=1;
                }
                else
                {
                    number=1;
                }
                continue;
            }
            
            if(start==1)
            {
                if(!(s[i]>='0'&&s[i]<='9'))
                {
                    if(end==1&&s[i]!=' ')
                        return false;
                    if(s[i]=='e'&&sign==0&&e==0&&number==1)
                    {
                        e=1;
                        continue;
                    }
                    if(s[i]=='.'&&point==0&&e==0)
                    {
                        point=1;
                        continue;
                    }
                    if((s[i]=='+'||s[i]=='-')&&e==1&&sign2==0&&last==0)
                    {
                        sign2=1;
                        continue;
                    }
                    
                    if(s[i]==' ')
                    {
                        end=1;
                        continue;
                    }
                    
                    return false;
                }
                if(end==1)
                    return false;
                
                if(e==1)
                {
                    last=1;
                }
                number=1;
                
                sign=0;
                
            }
        }
        
        
        if(last==0&&e==1)
            return false;
        if(number==0)
        {
            return false;
        }
        return true;
        
    }
};

你可能感兴趣的:(LeetCode 65. Valid Number)