Loading content...
You are given a text string s and a pattern string p. Your task is to implement a pattern matching engine that determines whether the pattern fully matches the entire text string. The pattern may contain two special metacharacters:
The goal is to return true if the pattern can describe the complete text string from start to finish, and false otherwise. Unlike partial matching, the pattern must account for every character in the text—no leftover or unmatched portions are allowed.
Key Observations:
s = "aa"
p = "a"falseThe pattern 'a' represents exactly one 'a' character. Since the text 'aa' contains two 'a' characters, the pattern cannot cover the entire string. The matching fails because there's an extra 'a' left unmatched.
s = "aa"
p = "a*"trueThe '' quantifier allows the preceding 'a' to repeat zero or more times. By using the '' to repeat 'a' twice, the pattern 'a*' successfully matches the entire text 'aa'. This demonstrates the power of the Kleene star operator.
s = "ab"
p = ".*"trueThe pattern '.' combines the wildcard '.' with the asterisk ''. The '.' matches any single character, and '' allows it to repeat any number of times. Together, '.' matches any string of any length, including 'ab'. This is the most permissive pattern possible.
Constraints