Why is_Match("a", "a*") is true?


  • 0
    X

    It is said that ' * ' Matches zero or more of the preceding element. In this way, "a*" could be "aa" or nothing. But how can "a*" match "a"?


  • 1
    T

    I believe that the statement ' "a*" could be "aa" or nothing' is incorrect. 'a*' can also be 'a'

    In the problem, it says: '*' Matches zero or more of the preceding element.

    Since the preceding element is 'a', * can represent nothing, 'a', 'aa', 'aaa', or any number of 'a's

    EDIT:
    That means that you can start with nothing, and add 'a's until we have the right number of 'a's.
    Sorry I accidentally misread something earlier.

    I hope this clarifies things!


  • 1
    X

    @teddochi thanks! You help me a lot!


  • 0
    T

    You're welcome! Glad it helped.


Log in to reply
 

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