1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/算法题(国内版)/problem (English)/模式匹配(English) [pattern-matching-lcci].html

39 lines
1.5 KiB
HTML
Raw Normal View History

2022-03-27 20:38:29 +08:00
<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>