Given an input string (s) and a pattern §, 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:
s could be empty and contains only lowercase letters a-z.
p could be empty and contains only lowercase letters a-z, and characters like ? or .
动态规划
字符串匹配问题
?能匹配一个字符
能匹配零个或多个字符
问p是不是s的模式串
1.设两个指针一个在s,一个在p
dp[i][j] s的前i个字符和p的前j个字符能不能匹配
2.动态规划的状态转移方程
如果s[i-1]==p[j-1]或者p[j-1]为?
那么
dp[i][j]=dp[i-1][j-1]
如果p[j-1]为,那么
dp[i][j]=dp[i-1][j] or dp[i][j-1] or dp[i-1][j-1]
依次对应的情况是匹配多个字符,零个字符和一个字符的情况。
3.初始状态
初始时所有dp的值为False
当s为空串,并且p也是空串的时候为真
当s为空串,并且p全是星号的时候也为真
那是否要考虑其他情况,不用其他的由从1开始的两个循环就能解决。