Regular Expression Matching 正则表达式匹配

来源:互联网 发布:鞋业erp软件xyerp 编辑:程序博客网 时间:2024/04/29 16:15
class Solution {
public:
    bool isMatch(const char *s, const char *p) {
        if(*p=='\0') return *s=='\0';
        if(*(p+1)!='*')
        {
            if(*s==*p||*p=='.'&&*s!='\0')
            {
                return isMatch(s+1,p+1);
            }
            else return false;
            
        }
        else
        {
            while(*s==*p||*p=='.'&&*s!='\0')
            {
                if(isMatch(s,p+2))
                return true;
                s++;  //pass as more as possible
            }
            return isMatch(s,p+2);//pass zero
        }
     }
};
0 0
原创粉丝点击