mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
39 lines
1.5 KiB
HTML
39 lines
1.5 KiB
HTML
<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 = "abba", value = "dogcatcatdog"
|
||
|
||
<strong>Output: </strong> true
|
||
|
||
</pre>
|
||
|
||
|
||
|
||
<p><strong>Example 2: </strong></p>
|
||
|
||
|
||
|
||
<pre>
|
||
|
||
<strong>Input: </strong> pattern = "abba", value = "dogcatcatfish"
|
||
|
||
<strong>Output: </strong> false
|
||
|
||
</pre>
|
||
|
||
|
||
|
||
<p><strong>Example 3: </strong></p>
|
||
|
||
|
||
|
||
<pre>
|
||
|
||
<strong>Input: </strong> pattern = "aaaa", value = "dogcatcatdog"
|
||
|
||
<strong>Output: </strong> false
|
||
|
||
</pre>
|
||
|
||
|
||
|
||
<p><strong>Example 4: </strong></p>
|
||
|
||
|
||
|
||
<pre>
|
||
|
||
<strong>Input: </strong> pattern = "abba", value = "dogdogdogdog"
|
||
|
||
<strong>Output: </strong> true
|
||
|
||
<strong>Explanation: </strong> "a"="dogdog",b="",vice versa.
|
||
|
||
</pre>
|
||
|
||
|
||
|
||
<p><strong>Note: </strong></p>
|
||
|
||
|
||
|
||
<ul>
|
||
|
||
<li><code>0 <= len(pattern) <= 1000</code></li>
|
||
|
||
<li><code>0 <= len(value) <= 1000</code></li>
|
||
|
||
<li><code>pattern</code> only contains <code>"a"</code> and <code>"b"</code>, <code>value</code> only contains lowercase letters.</li>
|
||
|
||
</ul>
|
||
|