Dynamic Programming
1 | class Solution { |
Remarks:
Use DP to reduce calculation
Two situations of handling
*:a. no occurrence so the current two patterns can be skipped (
ab*- >awhen there’s nob)b. one or more times: the current
*will absorb the last string char, and check the previous onedp[i][j]->dp[i-1][j], while the position/length of the current pattern keeps unchanged