Class Solution
java.lang.Object
g2401_2500.s2490_circular_sentence.Solution
2490 - Circular Sentence.<p>Easy</p>
<p>A <strong>sentence</strong> is a list of words that are separated by a <strong>single</strong> space with no leading or trailing spaces.</p>
<ul>
<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, <code>"hello world hello world"</code> are all sentences.</li>
</ul>
<p>Words consist of <strong>only</strong> uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.</p>
<p>A sentence is <strong>circular</strong> if:</p>
<ul>
<li>The last character of a word is equal to the first character of the next word.</li>
<li>The last character of the last word is equal to the first character of the first word.</li>
</ul>
<p>For example, <code>"leetcode exercises sound delightful"</code>, <code>"eetcode"</code>, <code>"leetcode eats soul"</code> are all circular sentences. However, <code>"Leetcode is cool"</code>, <code>"happy Leetcode"</code>, <code>"Leetcode"</code> and <code>"I like Leetcode"</code> are <strong>not</strong> circular sentences.</p>
<p>Given a string <code>sentence</code>, return <code>true</code> <em>if it is circular</em>. Otherwise, return <code>false</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> sentence = “leetcode exercises sound delightful”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> The words in sentence are [“leetcode”, “exercises”, “sound”, “delightful”].</p>
<ul>
<li>leetcod<ins>e</ins>’s last character is equal to <ins>e</ins>xercises’s first character.</li>
<li>exercise<ins>s</ins>’s last character is equal to <ins>s</ins>ound’s first character.</li>
<li>soun<ins>d</ins>’s last character is equal to <ins>d</ins>elightful’s first character.</li>
<li>delightfu<ins>l</ins>’s last character is equal to <ins>l</ins>eetcode’s first character.</li>
</ul>
<p>The sentence is circular.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> sentence = “eetcode”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> The words in sentence are [“eetcode”].</p>
<ul>
<li>eetcod<ins>e</ins>’s last character is equal to <ins>e</ins>etcode’s first character. The sentence is circular.</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> sentence = “Leetcode is cool”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The words in sentence are [“Leetcode”, “is”, “cool”]. - Leetcod<ins>e</ins>’s last character is <strong>not</strong> equal to <ins>i</ins>s’s first character. The sentence is <strong>not</strong> circular.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= sentence.length <= 500</code></li>
<li><code>sentence</code> consist of only lowercase and uppercase English letters and spaces.</li>
<li>The words in <code>sentence</code> are separated by a single space.</li>
<li>There are no leading or trailing spaces.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isCircularSentence
-