Regular Expression Matching

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*'. This is a classic hard memoization problem because the same suffix states are reached many times.

Input Format

s = text string, p = pattern with '.' and '*'

Output Format

true if s matches p, otherwise false

Constraints

  • 0 <= s.length, p.length <= 20

Examples

Example 1:

Input:

s = "aa"
p = "a*"

Output:

true

Explanation:

'*' allows multiple 'a' characters.

Example 2:

Input:

s = "ab"
p = ".*"

Output:

true

Explanation:

'.*' can match any string.

Loading...
Regular Expression Matching - Dp Fundamentals