java.lang.Object
g0001_0100.s0010_regular_expression_matching.Solution

public class Solution extends Object
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 = &ldquo;aa&rdquo;, p = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> &ldquo;a&rdquo; does not match the entire string &ldquo;aa&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aa&rdquo;, p = &ldquo;a*&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &lsquo;*&rsquo; means zero or more of the preceding element, &lsquo;a&rsquo;. Therefore, by repeating &lsquo;a&rsquo; once, it becomes &ldquo;aa&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;ab&rdquo;, p = &ldquo;.*&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &ldquo;.*&rdquo; means &ldquo;zero or more (*) of any character (.)&rdquo;.</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> s = &ldquo;aab&rdquo;, p = &ldquo;c*a*b&rdquo;</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 &ldquo;aab&rdquo;.</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> s = &ldquo;mississippi&rdquo;, p = &ldquo;mis*is*p*.&rdquo;</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 Details

    • Solution

      public Solution()
  • Method Details