Write your own recursive method complexity is too high, the method of preparing the backpack nine dp talk a good look, a lot of debt owed Yeah, WDNMD.
Given a string (s) and a character mode (p), to support the realization of a '?' And '*' wildcard match.
'?' Matches any single character.
'*' Matches any string (including the empty string).
Two strings match exact match is considered successful.
Description:
s may be empty, and only lowercase letters az from the.
p may be empty and contain only lowercase letters from az, and characters? and *.
DP [i] [j] represents the matching of the first j characters before i-th character of s and p, is set to match the symbol ~, s = s'n, p = p'q. n and q are two symbols are comparative.
1, when q! = '*' Is:
Only n ~ q, namely: n = q || q == '? 'Time,
s and p possible match: dp [i] [j] = dp [i - 1] [j - 1];
2, when q == '*', then q may correspond to 0 or 1 or more characters
When q is 0 corresponds to the character, determining s'n and p 'match, i.e. dp [i] [j] = dp [i] [j - 1]
When q is equivalent to a character judgment s 'and p' match, dp [i] [j] = dp [i-1] [j - 1]
When q is equivalent to a plurality of characters, determining s' matches p'q, dp [i] [j] = dp [i-1] [j]
About a third case '*' when q ==, when a plurality of characters corresponding to q Description:
Since q and assuming * * identified as a plurality of replacement case, at this time if you want to match from the * q * Proton a replacement for a character, and this sub-out * n match each other out, but because of q * where a plurality of characters are replaced, in which case separation of a * corresponds to match n, for the remaining matches * s' string. Therefore dp [i] [j] depends on the fact s' matches to p'q, i.e. dp [i] [j] = dp [i-1] [j].