-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from niharikah005/Leetcode-3238
Added solution to Leetcode 3238
- Loading branch information
Showing
1 changed file
with
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Leetcode 3238 - Number of Winning Players | ||
|
||
''' | ||
Problem: | ||
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player xi picked a ball of color yi. | ||
Player i wins the game if they pick strictly more than i balls of the same color. In other words, | ||
Player 0 wins if they pick any ball. | ||
Player 1 wins if they pick at least two balls of the same color. | ||
... | ||
Player i wins if they pick at leasti + 1 balls of the same color. | ||
Return the number of players who win the game. | ||
Note that multiple players can win the game.''' | ||
|
||
class Solution: | ||
def winningPlayerCount(self, n: int, pick) -> int: | ||
r = 0 | ||
cs = {} | ||
rs = [0]*n | ||
for i,k in pick: | ||
if i not in cs: | ||
cs[i]={} | ||
if k not in cs[i]: | ||
cs[i][k]=0 | ||
cs[i][k]+=1 | ||
if cs[i][k]>i: | ||
rs[i]=1 | ||
return sum(rs) | ||
|