首页 > 代码库 > [Leetcode] Wildcard Matching

[Leetcode] Wildcard Matching

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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "*") → trueisMatch("aa", "a*") → trueisMatch("ab", "?*") → trueisMatch("aab", "c*a*b") → false

Solution:
贪心算法:
http://blog.unieagle.net/2012/11/07/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Awildcard-matching/

只需要依据连续的’*’,将p分割成一些不带’*’的子串。然后在s中依次匹配就好了,只不过需要特殊照顾一下首尾两个子串:
1.对于开头不是’*’的p,第一个子串必须从s[0]开始匹配
2.对于结尾不是’*’的p,最后一个子串必须在s的尾巴上匹配


[Leetcode] Wildcard Matching