You are given a string sentence containing English words separated by spaces.
Treat the words as a circle: each word must end with the character that starts the following word, including the connection from the final word back to the first. Return true when every connection matches, or false otherwise. Comparisons are case-sensitive.
Example 1:
Input: sentence = "ab bc ca"
Output: trueExplanation: The three connections match on b, c, and a.
Example 2:
Input: sentence = "abca"
Output: trueExplanation: With one word, its two end characters must match.
Example 3:
Input: sentence = "ab ca"
Output: falseExplanation: The first word ends in b, but the next starts with c.
Constraints:
1 <= sentence.length <= 500- Only English letters (
a-z,A-Z) and spaces occur. - Consecutive words have exactly one separating space; neither end contains a space.