标签:mat bsp div cte har pre matching sub style
自己写了一下午,总是考虑不全,看了一个版本,使用递归,豁然开朗
class Solution { public: bool isMatch(string s, string p) { if (p.empty()) return s.empty(); if (‘*‘ == p[1]) // x* matches empty string or at least one character: x* -> xx* // *s is to ensure s is non-empty return (isMatch(s, p.substr(2)) || !s.empty() && (s[0] == p[0] || ‘.‘ == p[0]) && isMatch(s.substr(1), p)); else return !s.empty() && (s[0] == p[0] || ‘.‘ == p[0]) && isMatch(s.substr(1), p.substr(1)); } };
10. Regular Expression Matching
标签:mat bsp div cte har pre matching sub style
原文地址:http://www.cnblogs.com/wuya-study/p/6506981.html