259. Regular Expression Matching

HardStringString

Given an input string s and a pattern p, return true if p matches the entire string. '.' matches any single character; '*' matches zero or more of the preceding element. Input: '"s", "p"'.

Input: '"s", "p"'.

Output: Boolean — true or false.

Examples

Example 1
Input: "aa", "a"
Output: false
Explanation: 'a' does not cover 'aa'.
Example 2
Input: "aa", "a*"
Output: true
Explanation: 'a*' matches 'aa'.
Example 3
Input: "aab", "c*a*b"
Output: true
Explanation: c* matches empty, a* matches aa.

Constraints

Asked by

AmazonAppleBloombergGoogleMetaMicrosoft
Solve this problem in the editor →