mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
45 lines
1.7 KiB
HTML
45 lines
1.7 KiB
HTML
|
<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>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>'.'</code> Matches any single character.</li>
|
|||
|
<li><code>'*'</code> Matches zero or more of the preceding element.</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p>The matching should cover the <strong>entire</strong> input string (not partial).</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
<p><strong>Example 1:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>Input:</strong> s = "aa", p = "a"
|
|||
|
<strong>Output:</strong> false
|
|||
|
<strong>Explanation:</strong> "a" does not match the entire string "aa".
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>Example 2:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>Input:</strong> s = "aa", p = "a*"
|
|||
|
<strong>Output:</strong> true
|
|||
|
<strong>Explanation:</strong> '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>Example 3:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>Input:</strong> s = "ab", p = ".*"
|
|||
|
<strong>Output:</strong> true
|
|||
|
<strong>Explanation:</strong> ".*" means "zero or more (*) of any character (.)".
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
<p><strong>Constraints:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= s.length <= 20</code></li>
|
|||
|
<li><code>1 <= p.length <= 30</code></li>
|
|||
|
<li><code>s</code> contains only lowercase English letters.</li>
|
|||
|
<li><code>p</code> contains only lowercase English letters, <code>'.'</code>, and <code>'*'</code>.</li>
|
|||
|
<li>It is guaranteed for each appearance of the character <code>'*'</code>, there will be a previous valid character to match.</li>
|
|||
|
</ul>
|