跳至主要内容

2582. Pass the Pillow

class Solution {
public:
int passThePillow(int n, int time)
{
int rounds = time / (n - 1);
int steps = time % (n - 1);

if (rounds % 2 == 0) return steps + 1;
return n - steps;
}
};
  • T: O(1)O(1)
  • S: O(1)O(1)