Class Solution
java.lang.Object
g0001_0100.s0010_regular_expression_matching.Solution
10 - Regular Expression Matching.<p>Hard</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “aa”, p = “a”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> “a” does not match the entire string “aa”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “aa”, p = “a*”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> ‘*’ means zero or more of the preceding element, ‘a’. Therefore, by repeating ‘a’ once, it becomes “aa”.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “ab”, p = “.*”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> “.*” means “zero or more (*) of any character (.)”.</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> s = “aab”, p = “c*a*b”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches “aab”.</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> s = “mississippi”, p = “mis*is*p*.”</p>
<p><strong>Output:</strong> false</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isMatch
-