Skip to content

Latest commit

 

History

History
112 lines (97 loc) · 2.29 KB

_2582. Pass the Pillow.md

File metadata and controls

112 lines (97 loc) · 2.29 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 06, 2024

Last updated : July 06, 2024


Related Topics : Math, Simulation

Acceptance Rate : 56.72 %


Solutions

Python

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

C

int passThePillow(int n, int time) {
    time %= 2 * (n - 1);
    if (time < n)
        return time + 1;
    time -= n - 1;
    return n - time;
}

C++

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;
    }
};

C#

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;
    }
}

Java

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;
    }
}

JavaScript

/**
 * @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;
};