Why isMatch( "aaa", "ab*a*c*a") is true?


  • 0
    S

    My understanding * >> [one copy preceding element] OR [ empty, 0,escape of preceding element]
    . >> any thing

    In this case, the "aaa" contains no b, so the * before b and c must be [ 0, empty]. So,
    isMatch( "aaa", "abaca") =isMatch( "aaa", "aaa") .

    Now isMatch( "aaa", "aa*a") = isMatch( "aaa", "aa") OR isMatch( "aaa", "aaaa") .
    In both condition above, the result is false.

    Why the answer is true?


  • 0
    A

    the expression can be written as a b* a* c* a If a letter has a star AFTER it, then it goes like this

    a b* a* c* a

    a 00 a 00 a

    which returns true.


  • 0
    S

    So the 3rd 0 is from the 2nd *. I misunderstanding is that * and its previous element a must be 0. Thanks :)


  • 3
    Y

    b* means there's 0'b' or 1'b' or multiples 'b's.
    So,
    ab * a * c * a means
    'a'->0'b'->1'a'->0'c'->'a'


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.