-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3380d3
commit efd44e5
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/fishercoder/solutions/fourththousand/_3238.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.fishercoder.solutions.fourththousand; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class _3238 { | ||
public static class Solution1 { | ||
public int winningPlayerCount(int n, int[][] pick) { | ||
int winners = 0; | ||
Map<Integer, int[]> map = new HashMap<>(); | ||
for (int[] p : pick) { | ||
int player = p[0]; | ||
int color = p[1]; | ||
int[] colors = map.getOrDefault(player, new int[11]); | ||
colors[color]++; | ||
map.put(player, colors); | ||
} | ||
for (Map.Entry<Integer, int[]> entry : map.entrySet()) { | ||
int player = entry.getKey(); | ||
int[] colors = entry.getValue(); | ||
for (int c : colors) { | ||
if (c >= player + 1) { | ||
winners++; | ||
break; | ||
} | ||
} | ||
} | ||
return winners; | ||
} | ||
} | ||
} |