Class Solution
Easy
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"
,"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 a word is equal to the first character of the next word.
- The last character of the last word is equal to the first character of the first word.
For example, "leetcode exercises sound delightful"
, "eetcode"
, "leetcode eats soul"
are all circular sentences. However, "Leetcode is cool"
, "happy Leetcode"
, "Leetcode"
and "I like Leetcode"
are not circular sentences.
Given a string sentence
, return true
if it is circular. Otherwise, return false
.
Example 1:
Input: sentence = βleetcode exercises sound delightfulβ
Output: true
Explanation: The words in sentence are [βleetcodeβ, βexercisesβ, βsoundβ, βdelightfulβ].
- leetcodeβs last character is equal to exercisesβs first character.
- exercisesβs last character is equal to soundβs first character.
- soundβs last character is equal to delightfulβs first character.
- delightfulβs last character is equal to leetcodeβs first character.
The sentence is circular.
Example 2:
Input: sentence = βeetcodeβ
Output: true
Explanation: The words in sentence are [βeetcodeβ].
- eetcodeβs last character is equal to eetcodeβs first character. The sentence is circular.
Example 3:
Input: sentence = βLeetcode is coolβ
Output: false
Explanation: The words in sentence are [βLeetcodeβ, βisβ, βcoolβ]. - Leetcodeβs last character is not equal to isβs first character. The sentence is not circular.
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.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isCircularSentence
-