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 (Chinese)/句子相似性 III [sentence-similarity-iii].html

53 lines
3.0 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>给定两个字符串&nbsp;<code>sentence1</code>&nbsp;&nbsp;<code>sentence2</code>,每个表示由一些单词组成的一个句子。句子是一系列由&nbsp;<strong>单个 </strong>空格分隔的&nbsp;<strong>单词</strong>,且开头和结尾没有多余空格。每个单词都只包含大写和小写英文字母。</p>
<p>如果两个句子&nbsp;<code>s1</code>&nbsp;&nbsp;<code>s2</code>&nbsp;,可以通过往其中一个句子插入一个任意的句子(可以是空句子)而得到另一个句子,那么我们称这两个句子是 <strong>相似的</strong>&nbsp;<strong>注意</strong>,插入的句子必须与现有单词用空白隔开。&nbsp;</p>
<p>比方说,</p>
<ul>
<li><code>s1 = "Hello Jane"</code>&nbsp;<code>s2 = "Hello my name is Jane"</code>,我们可以往 <code>s1</code>&nbsp;&nbsp;<code>"Hello"</code>&nbsp;<code>"Jane"</code>&nbsp;之间插入&nbsp;<code>"my name is"</code>&nbsp;得到 <code>s2</code>&nbsp;</li>
<li><code>s1 = "Frog cool"</code>&nbsp;<code>s2 = "Frogs are cool"</code>&nbsp;不是相似的,因为尽管往&nbsp;<code>s1</code>&nbsp;中插入&nbsp;<code>"s are"</code>,它没有与&nbsp;<code>"Frog"</code>&nbsp;用空格隔开。</li>
</ul>
<p>给你两个句子&nbsp;<code>sentence1</code>&nbsp;<code>sentence2</code>&nbsp;,如果<em>&nbsp;</em><code>sentence1</code><em>&nbsp;</em><code>sentence2</code><strong>相似</strong> 的,请你返回&nbsp;<code>true</code>&nbsp;,否则返回&nbsp;<code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<div class="example-block"><b>输入:</b>sentence1 = "My name is Haley", sentence2 = "My Haley"</div>
<div class="example-block"><b>输出:</b>true</div>
<div class="example-block"><b>解释:</b>可以往 <code>sentence2</code> 中 "My" 和 "Haley" 之间插入 "name is" ,得到 <code>sentence1</code></div>
<div class="example-block">&nbsp;</div>
<p><strong>示例 2</strong></p>
<div class="example-block"><b>输入:</b>sentence1 = "of", sentence2 = "A lot of words"</div>
<div class="example-block"><b>输出:</b>false</div>
<div class="example-block"><strong>解释:</strong>没法往这两个句子中的一个句子只插入一个句子就得到另一个句子。</div>
<div class="example-block">&nbsp;</div>
<p><strong>示例 3</strong></p>
<div class="example-block"><b>输入:</b>sentence1 = "Eating right now", sentence2 = "Eating"</div>
<div class="example-block"><b>输出:</b>true</div>
<div class="example-block"><b>解释:</b>可以往 <code>sentence2</code> 的结尾插入 "right now" 得到 <code>sentence1</code></div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= sentence1.length, sentence2.length &lt;= 100</code></li>
<li><code>sentence1</code>&nbsp;&nbsp;<code>sentence2</code>&nbsp;都只包含大小写英文字母和空格。</li>
<li><code>sentence1</code>&nbsp;&nbsp;<code>sentence2</code>&nbsp;中的单词都只由单个空格隔开。</li>
</ul>