Regular Expression Matching, is a LeetCode problem from dynamic-programming subdomain. In this post we will see how we can solve this challenge in Swift

Problem Description

You can find the full details of the problem Regular Expression Matching at LeetCode

Solution

Note: A simple recursion violates the time limit. We need to first simplify the pattern in the following ways:

  1. a*a* -> a*      merge identical "x*"s

  2. a*b*.*c*d* -> .*    ignore all the "x*"s before and after ".*"

Time Complexity: O(n), Space Complexity: O(n)

Please check the main.swift snippet for the solution.

This solution originally posted at: Github by @soapyigu