|
| 1 | +<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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, <code>"hello world hello world"</code> are all sentences.</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Words consist of <strong>only</strong> uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.</p> |
| 8 | + |
| 9 | +<p>A sentence is <strong>circular </strong>if:</p> |
| 10 | + |
| 11 | +<ul> |
| 12 | + <li>The last character of a word is equal to the first character of the next word.</li> |
| 13 | + <li>The last character of the last word is equal to the first character of the first word.</li> |
| 14 | +</ul> |
| 15 | + |
| 16 | +<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> |
| 17 | + |
| 18 | +<p>Given a string <code>sentence</code>, return <code>true</code><em> if it is circular</em>. Otherwise, return <code>false</code>.</p> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | +<p><strong class="example">Example 1:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> sentence = "leetcode exercises sound delightful" |
| 25 | +<strong>Output:</strong> true |
| 26 | +<strong>Explanation:</strong> The words in sentence are ["leetcode", "exercises", "sound", "delightful"]. |
| 27 | +- leetcod<u>e</u>'s last character is equal to <u>e</u>xercises's first character. |
| 28 | +- exercise<u>s</u>'s last character is equal to <u>s</u>ound's first character. |
| 29 | +- soun<u>d</u>'s last character is equal to <u>d</u>elightful's first character. |
| 30 | +- delightfu<u>l</u>'s last character is equal to <u>l</u>eetcode's first character. |
| 31 | +The sentence is circular.</pre> |
| 32 | + |
| 33 | +<p><strong class="example">Example 2:</strong></p> |
| 34 | + |
| 35 | +<pre> |
| 36 | +<strong>Input:</strong> sentence = "eetcode" |
| 37 | +<strong>Output:</strong> true |
| 38 | +<strong>Explanation:</strong> The words in sentence are ["eetcode"]. |
| 39 | +- eetcod<u>e</u>'s last character is equal to <u>e</u>etcode's first character. |
| 40 | +The sentence is circular.</pre> |
| 41 | + |
| 42 | +<p><strong class="example">Example 3:</strong></p> |
| 43 | + |
| 44 | +<pre> |
| 45 | +<strong>Input:</strong> sentence = "Leetcode is cool" |
| 46 | +<strong>Output:</strong> false |
| 47 | +<strong>Explanation:</strong> The words in sentence are ["Leetcode", "is", "cool"]. |
| 48 | +- Leetcod<u>e</u>'s last character is <strong>not</strong> equal to <u>i</u>s's first character. |
| 49 | +The sentence is <strong>not</strong> circular.</pre> |
| 50 | + |
| 51 | +<p> </p> |
| 52 | +<p><strong>Constraints:</strong></p> |
| 53 | + |
| 54 | +<ul> |
| 55 | + <li><code>1 <= sentence.length <= 500</code></li> |
| 56 | + <li><code>sentence</code> consist of only lowercase and uppercase English letters and spaces.</li> |
| 57 | + <li>The words in <code>sentence</code> are separated by a single space.</li> |
| 58 | + <li>There are no leading or trailing spaces.</li> |
| 59 | +</ul> |
0 commit comments