File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff 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+ | 3175 | [Find The First Player to win K Games in a Row](https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3175.java) | | Medium |
1112| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3174.java) | | Easy |
1213| 3164 | [Find the Number of Good Pairs II](https://leetcode.com/problems/find-the-number-of-good-pairs-ii/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3164.java) | | Medium |
1314| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3162.java) | | Easy |
Original file line number Diff line number Diff line change 1+ package com .fishercoder .solutions ;
2+
3+ import java .util .Deque ;
4+ import java .util .LinkedList ;
5+
6+ public class _3175 {
7+ public static class Solution1 {
8+ public int findWinningPlayer (int [] skills , int k ) {
9+ Deque <int []> q = new LinkedList <>();
10+ int highestSkill = 0 ;
11+ for (int i = 0 ; i < skills .length ; i ++) {
12+ q .offer (new int []{i , skills [i ], 0 });
13+ highestSkill = Math .max (highestSkill , skills [i ]);
14+ }
15+ int count = 0 ;
16+ while (true ) {
17+ int [] first = q .pollFirst ();
18+ if (first [1 ] == highestSkill ) {
19+ //if the highest skill stands at the head of the queue, then it'll keep standing there
20+ //so it's guaranteed that it'll be the winner
21+ return first [0 ];
22+ }
23+ int [] second = q .pollFirst ();
24+ if (first [2 ] >= k ) {
25+ return first [0 ];
26+ }
27+ if (first [1 ] > second [1 ]) {
28+ first [2 ]++;
29+ q .addLast (second );
30+ q .addFirst (first );
31+ } else {
32+ second [2 ]++;
33+ q .addFirst (second );
34+ q .addLast (first );
35+ }
36+ count ++;
37+ }
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ package com .fishercoder ;
2+
3+ import com .fishercoder .solutions ._3175 ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import static org .junit .jupiter .api .Assertions .assertEquals ;
8+
9+ public class _3175Test {
10+ private static _3175 .Solution1 solution1 ;
11+ private static int [] skills ;
12+ private static int k ;
13+
14+ @ BeforeEach
15+ public void setup () {
16+ solution1 = new _3175 .Solution1 ();
17+ }
18+
19+ @ Test
20+ public void test1 () {
21+ skills = new int []{16 , 4 , 7 , 17 };
22+ k = 562084119 ;
23+ assertEquals (3 , solution1 .findWinningPlayer (skills , k ));
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments