1171. Regular Expression Matching (. and *)

EasyDynamic ProgrammingSequence DP

Given a string s and a pattern p containing lowercase letters, '.' (matches any single character), and '*' (matches zero or more of the preceding element), determine whether p matches the entire string s. Return true or false. The input is JSON {s, p}.

Input: JSON {s, p}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s":"aa","p":"a*"}
Output: true
Explanation: 'a*' matches 'aa'.
Example 2
Input: {"s":"ab","p":".*"}
Output: true
Explanation: '.*' matches any string.
Example 3
Input: {"s":"mississippi","p":"mis*is*p*."}
Output: false
Explanation: Pattern fails to match.

Constraints

Asked by

AmazonAppleBloombergGoogleMetaMicrosoft
Solve this problem in the editor →