mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
35 lines
1.8 KiB
HTML
35 lines
1.8 KiB
HTML
|
<p>你有两个字符串,即<code>pattern</code>和<code>value</code>。 <code>pattern</code>字符串由字母<code>"a"</code>和<code>"b"</code>组成,用于描述字符串中的模式。例如,字符串<code>"catcatgocatgo"</code>匹配模式<code>"aabab"</code>(其中<code>"cat"</code>是<code>"a"</code>,<code>"go"</code>是<code>"b"</code>),该字符串也匹配像<code>"a"</code>、<code>"ab"</code>和<code>"b"</code>这样的模式。但需注意<code>"a"</code>和<code>"b"</code>不能同时表示相同的字符串。编写一个方法判断<code>value</code>字符串是否匹配<code>pattern</code>字符串。</p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong> pattern = "abba", value = "dogcatcatdog"
|
|||
|
<strong>输出:</strong> true
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong> pattern = "abba", value = "dogcatcatfish"
|
|||
|
<strong>输出:</strong> false
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 3:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong> pattern = "aaaa", value = "dogcatcatdog"
|
|||
|
<strong>输出:</strong> false
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 4:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong> pattern = "abba", value = "dogdogdogdog"
|
|||
|
<strong>输出:</strong> true
|
|||
|
<strong>解释:</strong> "a"="dogdog",b="",反之也符合规则
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= len(pattern) <= 1000</code></li>
|
|||
|
<li><code>0 <= len(value) <= 1000</code></li>
|
|||
|
<li>你可以假设<code>pattern</code>只包含字母<code>"a"</code>和<code>"b"</code>,<code>value</code>仅包含小写字母。</li>
|
|||
|
</ul>
|