[LeetCode] 2490. Circular Sentence

김민우·2023년 1월 21일
0

알고리즘

목록 보기
119/189

- Problem

2490. Circular Sentence

- 내 풀이

class Solution:
    def isCircularSentence(self, sentence: str) -> bool:
        sentences = sentence.split()
        
        N = len(sentences)
        for i in range(N-1):
            if sentences[i][-1] != sentences[i+1][0]:
                return False

        return sentence[0] == sentence[-1]

- short code

class Solution:
    def isCircularSentence(self, sentence: str) -> bool:
        sentences = sentence.split()    
        return all(sentences[i][-1] == sentences[i+1][0] for i in range(len(sentences)-1)) and sentence[0] == sentence[-1]

- 결과

profile
Pay it forward.

0개의 댓글