[Leetcode] Wildcard Matching 通配符匹配

https://segmentfault.com/a/1190000003786247
答案中有一个很奇怪的地方,为什么遇到*之后不能直接默认完成匹配?
问题:

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", "c
a*b") → false

部分解答:

1.s的字符和p的字符相等
2.p中的字符是?,这时无论s的字符是什么都可以匹配一个
3.p中遇到了一个,这时无论s的字符是什么都没关系
4.之前的都不符合,但是p在之前的位置有一个
,我们可以从上一个后面开始匹配
5.s已经匹配完,但是p后面还有很多连续的`

疑问:(?)
答案中的4.5没有必要,可以直接遇到3之后,确认匹配成功。因为答案只需要true/false,除非*的匹配是有条件的,不匹配换行,字符串中可能有多行等情况

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容