java.lang.Object
g1801_1900.s1813_sentence_similarity_iii.Solution

public class Solution extends Object
1813 - Sentence Similarity III.<p>Medium</p> <p>A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, <code>&quot;Hello World&quot;</code>, <code>&quot;HELLO&quot;</code>, <code>&quot;hello world hello world&quot;</code> are all sentences. Words consist of <strong>only</strong> uppercase and lowercase English letters.</p> <p>Two sentences <code>sentence1</code> and <code>sentence2</code> are <strong>similar</strong> if it is possible to insert an arbitrary sentence <strong>(possibly empty)</strong> inside one of these sentences such that the two sentences become equal. For example, <code>sentence1 = &quot;Hello my name is Jane&quot;</code> and <code>sentence2 = &quot;Hello Jane&quot;</code> can be made equal by inserting <code>&quot;my name is&quot;</code> between <code>&quot;Hello&quot;</code> and <code>&quot;Jane&quot;</code> in <code>sentence2</code>.</p> <p>Given two sentences <code>sentence1</code> and <code>sentence2</code>, return <code>true</code> <em>if</em> <code>sentence1</code> <em>and</em> <code>sentence2</code> <em>are similar.</em> Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> sentence1 = &ldquo;My name is Haley&rdquo;, sentence2 = &ldquo;My Haley&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> sentence2 can be turned to sentence1 by inserting &ldquo;name is&rdquo; between &ldquo;My&rdquo; and &ldquo;Haley&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> sentence1 = &ldquo;of&rdquo;, sentence2 = &ldquo;A lot of words&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> No single sentence can be inserted inside one of the sentences to make it equal to the other.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> sentence1 = &ldquo;Eating right now&rdquo;, sentence2 = &ldquo;Eating&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> sentence2 can be turned to sentence1 by inserting &ldquo;right now&rdquo; at the end of the sentence.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= sentence1.length, sentence2.length <= 100</code></li> <li><code>sentence1</code> and <code>sentence2</code> consist of lowercase and uppercase English letters and spaces.</li> <li>The words in <code>sentence1</code> and <code>sentence2</code> are separated by a single space.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • areSentencesSimilar

      public boolean areSentencesSimilar(String sentence1, String sentence2)