|
1 | 1 | # [2490.Circular Sentence][title] |
2 | 2 |
|
3 | | -> [!WARNING|style:flat] |
4 | | -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 | | -
|
6 | 3 | ## Description |
| 4 | +A **sentence** is a list of words that are separated by a **single** space with no leading or trailing spaces. |
| 5 | + |
| 6 | +- For example, `"Hello World"`, `"HELLO"`, `"hello world hello world"` are all sentences. |
| 7 | + |
| 8 | +Words consist of **only** uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different. |
| 9 | + |
| 10 | +A sentence is **circular** if: |
| 11 | + |
| 12 | +- The last character of a word is equal to the first character of the next word. |
| 13 | +- The last character of the last word is equal to the first character of the first word. |
| 14 | + |
| 15 | +For example, `"leetcode exercises sound delightful"`, `"eetcode"`, `"leetcode eats soul"` are all circular sentences. However, `"Leetcode is cool"`, `"happy Leetcode"`, `"Leetcode"` and `"I like Leetcode"` are **not** circular sentences. |
| 16 | + |
| 17 | +Given a string `sentence`, return `true` if it is circular. Otherwise, return `false`. |
7 | 18 |
|
8 | 19 | **Example 1:** |
9 | 20 |
|
10 | 21 | ``` |
11 | | -Input: a = "11", b = "1" |
12 | | -Output: "100" |
| 22 | +Input: sentence = "leetcode exercises sound delightful" |
| 23 | +Output: true |
| 24 | +Explanation: The words in sentence are ["leetcode", "exercises", "sound", "delightful"]. |
| 25 | +- leetcode's last character is equal to exercises's first character. |
| 26 | +- exercises's last character is equal to sound's first character. |
| 27 | +- sound's last character is equal to delightful's first character. |
| 28 | +- delightful's last character is equal to leetcode's first character. |
| 29 | +The sentence is circular. |
13 | 30 | ``` |
14 | 31 |
|
15 | | -## 题意 |
16 | | -> ... |
17 | | -
|
18 | | -## 题解 |
| 32 | +**Example 2:** |
19 | 33 |
|
20 | | -### 思路1 |
21 | | -> ... |
22 | | -Circular Sentence |
23 | | -```go |
| 34 | +``` |
| 35 | +Input: sentence = "eetcode" |
| 36 | +Output: true |
| 37 | +Explanation: The words in sentence are ["eetcode"]. |
| 38 | +- eetcode's last character is equal to eetcode's first character. |
| 39 | +The sentence is circular. |
24 | 40 | ``` |
25 | 41 |
|
| 42 | +**Example 3:** |
| 43 | + |
| 44 | +``` |
| 45 | +Input: sentence = "Leetcode is cool" |
| 46 | +Output: false |
| 47 | +Explanation: The words in sentence are ["Leetcode", "is", "cool"]. |
| 48 | +- Leetcode's last character is not equal to is's first character. |
| 49 | +The sentence is not circular. |
| 50 | +``` |
26 | 51 |
|
27 | 52 | ## 结语 |
28 | 53 |
|
|
0 commit comments