801. Regular Expression Matching (Recursive)

HardRecursionRecursion

Given string s and pattern p with '.' (any single char) and '*' (zero or more of preceding element), return true if p matches the entire s.

Input: Two quoted strings: "s", "p".

Output: Boolean.

Examples

Example 1
Input: "aa", "a"
Output: false
Explanation: Single 'a' doesn't match 'aa'.
Example 2
Input: "aa", "a*"
Output: true
Explanation: 'a*' matches zero or more 'a's.
Example 3
Input: "ab", ".*"
Output: true
Explanation: '.*' matches any string.

Constraints

Asked by

AmazonAppleBloombergGoogleMetaMicrosoft
Solve this problem in the editor →