2490. Circular Sentence
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 70% Topics: String
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# string
class Solution(object):
def isCircularSentence(self, sentence):
"""
:type sentence: str
:rtype: bool
"""
return sentence[0] == sentence[-1] and all(sentence[i-1] == sentence[i+1]for i in xrange(len(sentence)) if sentence[i] == ' ')
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions