2582.cpp (164B)
1 class Solution { 2 public: 3 int passThePillow(int n, int time) const { 4 time = time % ((n - 1) * 2) + 1; 5 return min(time, n * 2 - time); 6 } 7 };