dsa · hard
Regular Expression Matching
Return whether the whole of s matches pattern p.
Arguments
s— the text that must match in fullp— pattern; "." is one char, "*" repeats the previous token
p uses two specials: "." matches any one character, and "*" matches zero or more of the token immediately before it (that token is a letter or "."). Every "*" has a preceding token — p is a valid pattern. Matching is of the entire string.
Example
s = "aa", p = "a" → false.
s = "aa", p = "a*" → true (a* is zero or more as).
s = "ab", p = ".*" → true (.* is zero or more of any character).
s = "aab", p = "c*a*b" → true (c* matches nothing, a* matches aa, then b).
Constraints
1 <= s.length <= 20 1 <= p.length <= 20 s contains only lowercase letters p contains lowercase letters, "." and "*" and is a valid pattern Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: "aa" "a" Expected: false
Example 2
Input: "aa" "a*" Expected: true
Example 3
Input: "ab" ".*" Expected: true