Wildcard Matching

来源:互联网 发布:人物关系网络 算法 编辑:程序博客网 时间:2024/05/18 21:08

和Regular Expression Matching类似,不过这里用递归超时


bool isMatch(const char *s, const char *p) {  
        if(*p=='\0')
            return *s=='\0';
        
        if(*p!='*')
            return ((*p==*s)||(*p=='?'&&*s!='\0'))&&isMatch(s+1,p+1);
            
        while(*s!='\0'){
            if(isMatch(s,p+1))
                return true;
            s++;
        }
        return false;
    }  

0 0
原创粉丝点击