From ef558d6ee0cf1b0df566edb4e3d8d58bc21f7531 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Sat, 2 Nov 2024 22:58:15 +0900 Subject: [PATCH] https://leetcode.com/problems/circular-sentence --- easy/circular_sentence.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 easy/circular_sentence.py diff --git a/easy/circular_sentence.py b/easy/circular_sentence.py new file mode 100644 index 0000000..809936b --- /dev/null +++ b/easy/circular_sentence.py @@ -0,0 +1,14 @@ +# https://leetcode.com/problems/circular-sentence + +class Solution: + def isCircularSentence(self, sentence: str) -> bool: + words = sentence.split(' ') + last = words[0][len(words[0]) - 1] + for word in words[1:]: + if last != word[0]: + return False + last = word[len(word) - 1] + + return last == words[0][0] + +