Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true

本文介绍了一种实现正则表达式匹配的算法,重点讨论了如何处理特殊字符'.'和'*'。通过两种方法实现了匹配逻辑:一种是递归方式,另一种是在递归基础上增加了缓存机制以提高效率。文章提供了具体的C++代码示例。
261

被折叠的 条评论
为什么被折叠?



