标签:reg amp turn tco class false ++ return ble
class Solution { public: bool match(string s, string p, int ss, int ps){ int psize = p.size(); int ssize = s.size(); while (ps < psize && ss < ssize){ char c = p[ps]; if (c != ‘.‘ && c != ‘*‘){ if (c != s[ss]){ return false; } ps ++; ss ++; continue; } if (c == ‘*‘){ if (ps == 0){ return false; } char p_last = s[ps-1]; if (p_last == ‘.‘){ p_last = s[ss-1]; } int sss = ss; while (sss < ssize && p_last == s[sss]){ if (match(s, p, ++sss, ps+1)){ return true; } } } ss ++; ps ++; } return (ps == psize && ss == ssize); } bool isMatch(string s, string p) { return match(s, p, 0, 0); } };
LeetCode problem 10: Regular Expression Matching
标签:reg amp turn tco class false ++ return ble
原文地址:http://www.cnblogs.com/nosaferyao/p/7857717.html