2582. Pass the Pillow
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 06, 2024
Last updated : July 06, 2024
Related Topics : Math, Simulation
Acceptance Rate : 56.72 %
class Solution:
def passThePillow(self, n: int, time: int) -> int:
time %= 2 * (n - 1) # Remove there and backs
if time < n :
return time + 1
time -= n - 1
return n - time
int passThePillow(int n, int time) {
time %= 2 * (n - 1);
if (time < n)
return time + 1;
time -= n - 1;
return n - time;
}
class Solution {
public:
int passThePillow(int n, int time) {
time %= 2 * (n - 1);
if (time < n)
return time + 1;
time -= n - 1;
return n - time;
}
};
public class Solution {
public int PassThePillow(int n, int time) {
time %= 2 * (n - 1);
if (time < n)
return time + 1;
time -= n - 1;
return n - time;
}
}
class Solution {
public int passThePillow(int n, int time) {
time %= 2 * (n - 1);
if (time < n)
return time + 1;
time -= n - 1;
return n - time;
}
}
/**
* @param {number} n
* @param {number} time
* @return {number}
*/
var passThePillow = function(n, time) {
time %= 2 * (n - 1);
if (time < n)
return time + 1;
time -= n - 1;
return n - time;
};