|
| 1 | +<h2><a href="https://leetcode.com/problems/regular-expression-matching">10. Regular Expression Matching</a></h2><h3>Hard</h3><hr><p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>'.'</code> Matches any single character.</li> |
| 5 | + <li><code>'*'</code> Matches zero or more of the preceding element.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>The matching should cover the <strong>entire</strong> input string (not partial).</p> |
| 9 | + |
| 10 | +<p> </p> |
| 11 | +<p><strong class="example">Example 1:</strong></p> |
| 12 | + |
| 13 | +<pre> |
| 14 | +<strong>Input:</strong> s = "aa", p = "a" |
| 15 | +<strong>Output:</strong> false |
| 16 | +<strong>Explanation:</strong> "a" does not match the entire string "aa". |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> s = "aa", p = "a*" |
| 23 | +<strong>Output:</strong> true |
| 24 | +<strong>Explanation:</strong> '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa". |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 3:</strong></p> |
| 28 | + |
| 29 | +<pre> |
| 30 | +<strong>Input:</strong> s = "ab", p = ".*" |
| 31 | +<strong>Output:</strong> true |
| 32 | +<strong>Explanation:</strong> ".*" means "zero or more (*) of any character (.)". |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= s.length <= 20</code></li> |
| 40 | + <li><code>1 <= p.length <= 20</code></li> |
| 41 | + <li><code>s</code> contains only lowercase English letters.</li> |
| 42 | + <li><code>p</code> contains only lowercase English letters, <code>'.'</code>, and <code>'*'</code>.</li> |
| 43 | + <li>It is guaranteed for each appearance of the character <code>'*'</code>, there will be a previous valid character to match.</li> |
| 44 | +</ul> |
0 commit comments