Text Pattern Matching with Stars
Problem statement
You are given a lowercase string text and a pattern pattern containing lowercase letters and the wildcard *.
- A lowercase letter matches the same letter.
- A
*matches any sequence of characters, including the empty sequence.
Return true if the entire pattern matches the entire text. Otherwise, return false.
Consecutive stars have the same meaning as a single star.
Function
matchesTextPattern(text: String, pattern: String) → booleanExamples
Example 1
text = "adceb"pattern = "*a*b"return = trueThe first star matches the empty prefix, and the second star matches dce.
Example 2
text = "acdcb"pattern = "a*c*d"return = falseThe final d cannot match the final b, regardless of how the stars expand.
Example 3
text = "abc"pattern = "***"return = trueThe consecutive stars collectively match the complete text.
Constraints
0 <= text.length <= 200000.1 <= pattern.length <= 200000.textcontains only lowercase English letters.patterncontains only lowercase English letters and*.