#2490
Easy Algorithms Circular sentence
String
70.2% acceptance
Feb 25, 2026
761
28
A sentence is circular if the last character of each word equals the first character
of its next word, and the last character of the last word equals the first character
of the first word.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn is_circular_sentence(sentence: String) -> bool {
let b = sentence.as_bytes();
let n = b.len();
if b[0] != b[n - 1] { return false; }
for i in 0..n - 1 {
if b[i] == b' ' && b[i - 1] != b[i + 1] { return false; }
}
true
}
}