JuniorString
Circular Sentence
A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
- For example,
"Hello World","HELLO", and"hello world hello world"are all sentences.
Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.
A sentence is circular if:
- The last character of each word in the sentence is equal to the first character of its next word.
- The last character of the last word is equal to the first character of the first word.
Given a string sentence, return true if it is circular. Otherwise, return false.
Example 1
Input
sentence = "leetcode exercises sound delightful"Output
trueEach word's last character matches the next word's first character, and the last word connects back to the first word.
Example 2
Input
sentence = "eetcode"Output
trueThe only word's last character is equal to its first character.
Constraints
- 1 <= sentence.length <= 500
- sentence consist of only lowercase and uppercase English letters and spaces.
- The words in sentence are separated by a single space.
- There are no leading or trailing spaces.