正则表达式算法实现

来源:互联网 发布:淘宝冲洗胶卷 编辑:程序博客网 时间:2024/05/20 11:25
class Solution {public:    bool isMatch(const char *s, const char *p) {        if(*s == '\0'){            if(*p == '\0') return true;            if(*p != '*') return false;        }        if(*p == '?') return isMatch(++s, ++p);        else if(*p == '*'){            while(*(++p) == '*');            for(; *s != '\0'; ++s){                if(isMatch(s, p)) return true;            }            return isMatch(s, p);        }else{            if(*p == *s) return isMatch(++s, ++p);            return false;        }        return false;    }};
时间复杂度略高。。。。
0 0
原创粉丝点击