2490. Circular Sentence Easy
1/**
2 * [2490] Circular Sentence
3 *
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 * A sentence is circular if:
10 *
11 * The last character of a word is equal to the first character of the next word.
12 * The last character of the last word is equal to the first character of the first word.
13 *
14 * 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.
15 * Given a string sentence, return true if it is circular. Otherwise, return false.
16 *
17 * <strong class="example">Example 1:
18 *
19 * Input: sentence = "leetcode exercises sound delightful"
20 * Output: true
21 * Explanation: The words in sentence are ["leetcode", "exercises", "sound", "delightful"].
22 * - leetcod<u>e</u>'s last character is equal to <u>e</u>xercises's first character.
23 * - exercise<u>s</u>'s last character is equal to <u>s</u>ound's first character.
24 * - soun<u>d</u>'s last character is equal to <u>d</u>elightful's first character.
25 * - delightfu<u>l</u>'s last character is equal to <u>l</u>eetcode's first character.
26 * The sentence is circular.
27 * <strong class="example">Example 2:
28 *
29 * Input: sentence = "eetcode"
30 * Output: true
31 * Explanation: The words in sentence are ["eetcode"].
32 * - eetcod<u>e</u>'s last character is equal to <u>e</u>etcode's first character.
33 * The sentence is circular.
34 * <strong class="example">Example 3:
35 *
36 * Input: sentence = "Leetcode is cool"
37 * Output: false
38 * Explanation: The words in sentence are ["Leetcode", "is", "cool"].
39 * - Leetcod<u>e</u>'s last character is not equal to <u>i</u>s's first character.
40 * The sentence is not circular.
41 *
42 * Constraints:
43 *
44 * 1 <= sentence.length <= 500
45 * sentence consist of only lowercase and uppercase English letters and spaces.
46 * The words in sentence are separated by a single space.
47 * There are no leading or trailing spaces.
48 *
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/circular-sentence/
53// discuss: https://leetcode.com/problems/circular-sentence/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58 pub fn is_circular_sentence(sentence: String) -> bool {
59 false
60 }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_2490() {
71 }
72}
73
Back
© 2025 bowen.ge All Rights Reserved.