Why is "aaba" "ab*a*c*a" not true?


  • 2
    X

    If I understand it correctly, * can mean "any string" or mean "remove the previous element", as seen in the isMatch("aab","cab)" case.

    If that is correct, abac*a can do the following:

    1. b* means removal of b, abaca becomes aac*a
    2. c* means removal of c, aaca becomes aaa
      so why does "aaba" not match "aa
      a"?

  • 1
    M

    A * means a string consisting of zero or more instances of the previous character, nothing else. It cannot insert new characters that did not exist in the string already.

    Look at the two strings again. The first, which must be matched, has 2 a's before the first b. The pattern only has one a before the b, and there are no other places the b could come from. Therefore, no strings with more than one a before the b can match that pattern.


Log in to reply
 

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