2582. Pass the Pillow
Problem
Approach
Math problem — find the pattern. With n people, the period is n-1. Number of full cycles = . If the number of full cycles is even, the pillow moves forward from the start; otherwise, it moves backward from the end.
Code
class Solution:
def passThePillow(self, n: int, time: int) -> int:
if n > time:
return time + 1
if time // (n-1) % 2 == 0:
return time % (n-1) + 1
else:
return n - time % (n-1)贡献者
这篇文章有帮助吗?
最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0