Implement wildcard pattern matching with support for ‘?’ and ‘*’.
‘?’ Matches any single character.
‘*’ Matches any sequence of characters (including the empty sequence).
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”, ““) ? true
isMatch(“aa”, “a“) ? true
isMatch(“ab”, “?“) ? true
isMatch(“aab”, “ca*b”) ? false
解法1:
这题的关键在于对于*的处理。
DP 不能过OJ
two pointers可以,关键思路是碰到*先从match 0个字符开始,往后继续match,如果发现不match了那就试着match 1个字符,以此类推。
最后要注意是否pattern还只剩*
C++
Java