classSolution{public:intpassThePillow(intn,inttime){// Repeat every (n - 1) * 2 seconds.time%=(n-1)*2;if(time<n)// Going forward from 1.return1+time;returnn-(time-(n-1));// Going backward from n.}};
123456789
classSolution{publicintpassThePillow(intn,inttime){// Repeat every (n - 1) * 2 seconds.time%=(n-1)*2;if(time<n)// Going forward from 1.return1+time;returnn-(time-(n-1));// Going backward from n.}}
1234567
classSolution:defpassThePillow(self,n:int,time:int)->int:# Repeat every (n - 1) * 2 seconds.time%=(n-1)*2iftime<n:# Going forward from 1.return1+timereturnn-(time-(n-1))# Going backward from n.