Regular Expression Matching

来源:互联网 发布:英国读研要求gpa算法 编辑:程序博客网 时间:2024/05/22 05:10

题目地址:点击打开链接

class Solution {public:    bool isMatch(string s, string p) {        return match(s,p,0,0);    }private:    bool match(string s,string p,int a,int b) {        int m=s.size();        int n=p.size();        if(a==m&&b==n)return true;        if(b==n)return false;        if(b==n-1||p[b+1]!='*'){            if(a<m&&(s[a]==p[b]||p[b]=='.'))return match(s,p,a+1,b+1);            return false;        }else{            if(match(s,p,a,b+2))return true;            while(a<m&&(s[a]==p[b]||p[b]=='.')){                if(match(s,p,a+1,b+2))return true;                ++a;            }            return false;        }    }};


0 0
原创粉丝点击