Wildcard Matching
Given an input string (s) and a pattern (p), 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).
Note:
scould be empty and contains only lowercase lettersa-z.pcould be empty and contains only lowercase lettersa-z, and characters like?or*.
Example
Example 1:
Input:
s = "aa"
p = "a"
Output:
false
Explanation:
"a" does not match the entire string "aa".Example 2:
Example 3:
Example 4:
Example 5:
Note
分类讨论:
当前字符相同的情况:
sChar == pChar || pChar == '?'相同或者pattern字符是"?",s和p都看下一个字符开头的子串p是"*"的情况:
p向后跳1位,对应"a*"是空的情况
s往后跳1位,对应一个或者多个字符序列的情况
递归边界:
““ == ”“的情况:p到头,s也要到头“” == "********"的情况,s到头,p必须all star
Memo:
二维boolean数组表示0到index的子串匹配情况
visited数组来记录是否在memo里出现
Code
Last updated