leetcode 44. Wildcard Matching
动态规划:
1:状态转移方程
if('?' == p[j - 1] || s[i - 1] == p[j - 1])
vvb[i][j] = vvb[i - 1][j - 1];
if('*' == p[j - 1])
vvb[i][j] = vvb[i][j - 1] || vvb[i - 1][j - 1] || vvb[i-1][j];
边界情况主要考虑两种:
1:s="abadfs",p="*"
2.s="",p="*"
class Solution
{
public:
bool isMatch(string s, string p)
{
int ls = s.size(), lp = p.size();
vector<vector<bool> > vvb(ls + 1, vector<bool>(lp + 1, false));
vvb[0][0] = true;
for(int j = 1; j <= lp; ++ j)
{
vvb[0][j] = vvb[0][j - 1] && '*' == p[j - 1];
for(int i = 1; i <= ls; ++ i)
{
vvb[i][0]=vvb[i-1][0] && '*' == p[0];
if('?' == p[j - 1] || s[i - 1] == p[j - 1])
vvb[i][j] = vvb[i - 1][j - 1];
else if('*' == p[j - 1])
vvb[i][j] = vvb[i][j - 1] || vvb[i - 1][j - 1] || vvb[i-1][j];
// cout<<i<<" "<<j<<" "<<vvb[i][j]<<endl;
}
}
return vvb[ls][lp];
}
};