Skip to content

Commit 8f2fb41

Browse files
solves #3178: Find the Child Who Has the Ball After K Seconds in java
1 parent a5d5471 commit 8f2fb41

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,9 @@
915915
| 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | |
916916
| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | [![Java](assets/java.png)](src/FindTheNumberOfGoodPairsI.java) | |
917917
| 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | [![Java](assets/java.png)](src/MinimumNumberOfChairsInAWaitingRoom.java) | |
918-
| 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | [![Java](assets/java.png)](src/ClearDigits.java) | |
919-
| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | |
920-
| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | | |
918+
| 3173 | 🔒 [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | |
919+
| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | [![Java](assets/java.png)](src/ClearDigits.java) | |
920+
| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | |
921921
| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | |
922922
| 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | |
923923
| 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | |

Diff for: src/FindTheChildWhoHasTheBallAfterKSeconds.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds
2+
// T: O(1)
3+
// S: O(1)
4+
5+
public class FindTheChildWhoHasTheBallAfterKSeconds {
6+
public int numberOfChild(int n, int k) {
7+
final boolean isLeftDirection = (k / (n - 1)) % 2 == 0;
8+
if (isLeftDirection) {
9+
return k % (n - 1);
10+
}
11+
return n - 1 - (k % (n - 1));
12+
}
13+
}

0 commit comments

Comments
 (0)