呵呵,又是堆栈溢出
正则表达式匹配
http://www.nowcoder.com/questionTerminal/45327ae22b7b413ea21df13ee7d6429c
class Solution {
public:
bool matchCore(char* str, char* pattern)
{
if(str=='\0'&&pattern=='\0') return true;
if(pattern=='\0') return false;
if ((pattern+1)=='')
{
return matchCore(str+1,pattern)||
matchCore(str+1,pattern+2)||
matchCore(str,pattern+2);
}
if(str==pattern||(pattern=='.'&&str!='\0'))
return matchCore(str+1,pattern+1);
return false;
}
bool match(char str, char* pattern)
{
if (str == nullptr || pattern == nullptr)
return false;
return matchCore(str, pattern);
}
};