반응형
Recent Posts
Notice
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 코딩테스트준비
- Python
- 항해99
- 99항해
- softeer
- 파이썬
- python 2309
- 알고리즘
- 혁펜하임
- leetcode
- BOJ
- BFS
- dfs
- 구현
- easy 딥러닝
- 백준
- 해시
- til
- 개발자취업
- 코딩테스트 준비
- 개발자 취업
- 큐
- 기능개발
- 스택
- 활성화 함수
- 프로그래머스
- boj 2309
- 99클럽
- 딥러닝
- 백준 2309
Archives
- Today
- Total
동까의 코딩
[99클럽] 33일차 TIL 본문
반응형
https://leetcode.com/problems/find-the-winner-of-the-circular-game/
class Node:
def __init__(self, v):
self.val = v
self.next = None
self.prev = None
class Solution:
def findTheWinner(self, n: int, k: int) -> int:
start_node = cur_node = Node(1)
prev_node = None
for i in range(2, n + 1):
new_node = Node(i)
cur_node.next = new_node
cur_node.prev = prev_node
prev_node = cur_node
cur_node = new_node
cur_node.next = start_node
cur_node.prev = prev_node
start_node.prev = cur_node
index = 1
cur_node = start_node
while cur_node.next.val != cur_node.val:
if index % k == 0:
cur_node.prev.next = cur_node.next
cur_node.next.prev = cur_node.prev
cur_node = cur_node.next
index += 1
return cur_node.val
반응형
'문제 풀이 > 99클럽' 카테고리의 다른 글
[99클럽] 35일차 TIL (0) | 2024.06.25 |
---|---|
[99클럽] 34일차 TIL (0) | 2024.06.23 |
[99클럽] 32일차 TIL (1) | 2024.06.21 |
[99클럽] 31일차 TIL (0) | 2024.06.20 |
[99클럽] 30일차 TIL (0) | 2024.06.19 |