Problem · String
Wildcard Matching with Stars
Learn this problemProblem statement
You are given a lowercase string text and a pattern pattern containing lowercase letters and the wildcard *.
A 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
matchesPattern(text: String, pattern: String) → booleanExamples
Example 1
text = "adceb"pattern = "*a*b"return = trueThe first star can match the empty prefix and the second star can match dce.
Example 2
text = "acdcb"pattern = "a*c*d"return = falseThe pattern requires a final d, but the text ends with b; no star expansion can change that literal mismatch.
Example 3
text = "abc"pattern = "***"return = trueConsecutive stars collectively match the entire text.
Constraints
0 <= text.length <= 200000.1 <= pattern.length <= 200000.textcontains lowercase English letters.patterncontains lowercase English letters and*.