leetpycode/medium/find_the_winner_of_the_circular_game.py

8 lines
259 B
Python

# https://leetcode.com/problems/find-the-winner-of-the-circular-game
class Solution:
def findTheWinner(self, n: int, k: int) -> int:
result = 1
for i in range(2, n + 1):
result = (result + k - 1) % i + 1
return result