선발대

[스파르타] 99클럽 2기 코테스터디 34일차 TIL / leet 1823 본문

스파르타코딩클럽/활동 내용

[스파르타] 99클럽 2기 코테스터디 34일차 TIL / leet 1823

신선한 스타트 2024. 6. 22. 23:48

Leetcode: 1823. Find the Winner of the Circular Game (링크)

 

1823. Find the Winner of the Circular Game

 

 

class Solution:
    def findTheWinner(self, n: int, k: int) -> int:
        q = deque([x + 1 for x in range(n)])
        while len(q) > 1:
            c = k - 1
            while c:
                q.append(q.popleft())
                c -= 1
            q.popleft()
        return q[0]

오늘 미들러 풀이 끝!


참고한 풀이: https://leetcode.com/problems/find-the-winner-of-the-circular-game/solutions/3985873/beginner-friendly-simple-solution-with-using-queue-ds-on-python3/

 

Comments