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
2562. Find the Array Concatenation Value
LeetCode 2562. Find the Array Concatenation Value — two-pointer approach to concatenate first and last numbers as strings and sum them, for intermediate Python learners.
2639. Find the Width of Columns of a Grid
LeetCode 2639. Find the Width of Columns of a Grid — compute max digit length per column in O(n²) using string conversion and column-wise iteration, ideal for grid traversal practice.