Class Solution

java.lang.Object
g0001_0100.s0044_wildcard_matching.Solution

public class Solution extends Object
44 - Wildcard Matching.<p>Hard</p> <p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>'?'</code> and <code>'*'</code> where:</p> <ul> <li><code>'?'</code> Matches any single character.</li> <li><code>'*'</code> Matches any sequence of characters (including the empty sequence).</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;*&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &lsquo;*&rsquo; matches any sequence.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;cb&rdquo;, p = &ldquo;?a&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> &lsquo;?&rsquo; matches &lsquo;c&rsquo;, but the second letter is &lsquo;a&rsquo;, which does not match &lsquo;b&rsquo;.</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> s = &ldquo;adceb&rdquo;, p = &ldquo;*a*b&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> The first &lsquo;*&rsquo; matches the empty sequence, while the second &lsquo;*&rsquo; matches the substring &ldquo;dce&rdquo;.</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> s = &ldquo;acdcb&rdquo;, p = &ldquo;a*c?b&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= s.length, p.length <= 2000</code></li> <li><code>s</code> contains only lowercase English letters.</li> <li><code>p</code> contains only lowercase English letters, <code>'?'</code> or <code>'*'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isMatch

      public boolean isMatch(String inputString, String pattern)