1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/模式匹配(English) [pattern-matching-lcci].html

39 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also matches patterns like a, ab, and b. Write a method to determine if value matches pattern. a and b cannot be the same string.</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong> pattern = &quot;abba&quot;, value = &quot;dogcatcatdog&quot;
<strong>Output: </strong> true
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong> pattern = &quot;abba&quot;, value = &quot;dogcatcatfish&quot;
<strong>Output: </strong> false
</pre>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong> pattern = &quot;aaaa&quot;, value = &quot;dogcatcatdog&quot;
<strong>Output: </strong> false
</pre>
<p><strong>Example 4: </strong></p>
<pre>
<strong>Input: </strong> pattern = &quot;abba&quot;, value = &quot;dogdogdogdog&quot;
<strong>Output: </strong> true
<strong>Explanation: </strong> &quot;a&quot;=&quot;dogdog&quot;,b=&quot;&quot;vice versa.
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>0 &lt;= len(pattern) &lt;= 1000</code></li>
<li><code>0 &lt;= len(value) &lt;= 1000</code></li>
<li><code>pattern</code>&nbsp;only contains&nbsp;<code>&quot;a&quot;</code>&nbsp;and&nbsp;<code>&quot;b&quot;</code>,&nbsp;<code>value</code> only contains lowercase letters.</li>
</ul>