MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / is_circular_sentence

Function is_circular_sentence

2490-circular-sentence.rs:1–19  ·  view source on GitHub ↗
(sentence: String)

Source from the content-addressed store, hash-verified

1pub fn is_circular_sentence(sentence: String) -> bool {
2 if sentence.chars().nth(0).unwrap() !=
3 sentence.chars().nth(sentence.len() - 1).unwrap() {
4 return false
5 }
6 let mut count = 0;
7 let mut prev_char: char = '?';
8 for word in sentence.split_ascii_whitespace() {
9 if count == 0 {
10 prev_char = word.chars().last().unwrap()
11 } else {
12 let curr_char = word.chars().nth(0).unwrap();
13 if curr_char != prev_char { return false }
14 prev_char = word.chars().last().unwrap();
15 }
16 count += 1
17 }
18 true
19}
20
21fn main() {
22 let sentence = "leetcode exercises sound delightful".to_string();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected