Skip to content

Commit 98e3511

Browse files
add 2582
1 parent b576738 commit 98e3511

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2582 |[Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2582.java) | | Easy |
1112
| 2566 |[Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2566.java) | | Easy |
1213
| 2562 |[Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2562.java) | | Easy |
1314
| 2559 |[Count Vowel Strings in Ranges](https://leetcode.com/problems/count-vowel-strings-in-ranges/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2559.java) | | Medium |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2582 {
4+
public static class Solution1 {
5+
public int passThePillow(int n, int time) {
6+
int person = 1;
7+
boolean goLeft = true;
8+
while (time-- > 0) {
9+
if (goLeft) {
10+
person++;
11+
} else {
12+
person--;
13+
}
14+
if (time == 0) {
15+
return person;
16+
}
17+
if (person == n || person == 1) {
18+
goLeft = !goLeft;
19+
}
20+
}
21+
return person;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)