这两天翻了很多题解,思路讲解方面总是要么不够清楚要么有些许漏洞,不易于像我这样的新手理解;现在我终于弄明白解题思路了,详细整理一下,希望能让更多的朋友少走弯路。
题目解析
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
s只能包含英文字母,p只能包含英文字母和'.','*';都可以为空
保证每次'*'出现前面必定有一个有效的可以用来匹配的字母元素
(不能出现连续的`'*'`)
目标是p的所有元素经过'*'和'.'处理之后与s相同
函数原型为:
bool isMatch(const char *s, const char *p)
举几个例子:
isMatch("aa","a") → false <- "a" does not match the entire string "aa"
isMatch("aa","aa") → true <- "aa" matches the entire "aa"
isMatch("aa", "a*") → true <- "*" means matches one or more preceding chars, 'a'*2 == "aa"
isMatch("aa", ".*") → true <- '.' 等于任意字符,'.*'指match