In the given examples, the last one
isMatch("aab", "c*a*b") → true; don't understand why these two strings matches?
Can someone please help me understand this example?
Please edit your question with markdown syntax. You could use backtick
` to quote the content
isMatch("aab", "c*a*b") → true, or the
* will miss.
Pay attention to this:
'*' Matches zero or more of the preceding element.
So for this testcase
"c*a*b" could be 0 c 2 a and 1 b, it matched aab.
No. Only match
* is only work on the preceding one element, not the whole string.
you have to combine '*' and its preceding element together.
they together represent 0~n preceding element.
based on this, the preceding element of'' can not be '' or empty
Still don't understand. No matter you put null or any characters for the *, the leading character of
c*a*b is always 'c', how could it match "aab" ?
According to the question,
* means zero of more PRECEDING element, which means we could have zero
c. However, by this logic,
isMatch("ab", ".*")→ true is not correct
Because "" Matches zero or more of the preceding element.So that "c" can have no c.
Then how about the
isMatch("ab", ".*")→ true one?
".*"means any length of the any character,so
isMatch("ab", ".*")→ true
You should learn more about Regular Expression.
The asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches "ac", "abc", "abbc", "abbbc", and so on.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.