Implement wildcard pattern matching with support‘?‘
And‘*‘
.
'? 'Matches any single character. '*' matches any sequence of characters (including the empty sequence). The matching shocould coverEntireInput string (not partial ). the function prototype shoshould be: bool ismatch (const char * s, const char * P) some examples: ismatch ("AA", "A") → falseismatch ("AA ", "AA") → trueismatch ("AAA", "AA") → falseismatch ("AA", "*") → trueismatch ("AA", "*") → trueismatch ("AB ","? * ") → Trueismatch (" AAB "," C * a * B ") → false
Solution:
Greedy Algorithm:
Http://blog.unieagle.net/2012/11/07/leetcode%E9%A2%98%E7%9B% AE %EF%BC%9Awildcard-matching/
You only need to separate P into substrings without '*' based on the continuous. Then match the strings in S, but you need to take special care of the first and last two substrings:
1. For P whose start is not '*', the first substring must start from S [0 ].
2. For P whose end is not '*', the last substring must match with the tail of S.
[Leetcode] wildcard matching