Skip to content

Commit b7d6b0f

Browse files
committed
Upsert 2490-circular-sentence.rs
1 parent 7e64e46 commit b7d6b0f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

2490-circular-sentence.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pub 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+
21+
fn main() {
22+
let sentence = "leetcode exercises sound delightful".to_string();
23+
println!("{:?}", is_circular_sentence(sentence));
24+
let sentence = "eetcode".to_string();
25+
println!("{:?}", is_circular_sentence(sentence));
26+
}

0 commit comments

Comments
 (0)