Leetcode 10 regular expression matching *

Learned Gangster blog: https: //www.cnblogs.com/willaty/p/8134672.html

A given pattern matching string s and p hereinafter "~" represents a matching

bool dp [i] [j] - 0 ~ i p characters and the characters 0 ~ j s matches

(1) p * does not exist -> bitwise to match

(2) p * has

   The substring s [0, i] can be expressed as s1 = Sx where S is the bit string x i-1 is composed of the i-th bit

   p is substring [0, j] can be expressed as P p1 = Pya wherein y is a front string composed of j-2 to j-1 th bit position of a j-th bit

   Calculating dp [i] [j] matches i.e. s1 and p1

    ①x = a case, if S ~ Py, i.e. the s1 ~ p1 dp [i] [j] = dp [i-1] [j-1]

    ②x!=a  ①a!=*  dp[i][j]=0

         ②a = * ①x! = Y if Sx ~ P s1 ~ p1 i.e., the dp [i] [j] = dp [i] [j-2]

             ②x = y S ~ P or if Sx ~ P or S ~ Py or Sx ~ Py or the S ~ Pya s1 ~ p1

                即dp[i][j]=dp[i-1][j-2]||dp[i][j-2]||dp[i-1][j-1]||dp[i][j-1]||dp[i-1][j]

 

Guess you like

Origin www.cnblogs.com/suuusu/p/10983713.html