File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments