winningPlayerCount

```dart []
class Solution {
  int winningPlayerCount(int n, List<List<int>> pick) {
      List<Player> players = List.generate(n, (e) => Player(id: e, balls: []));
  Set<Player> winners = {};
  for (int i = 0; i < pick.length; i++) {
    Player? player;

    try {
      player = players.firstWhere((e) => e.id == pick[i][0]);
      int oneColorCount = player.addBall(pick[i][1]);
     if (player.id == 0) {
        winners.add(player);
      } else if (player.id + 1 <= oneColorCount) {
        winners.add(player);
      }
    } catch (e) {}
  }
  return winners.length;

  }
}
class Player {
  int id;
  List<Ball> balls;
  Player({
    required this.id,
    required this.balls,
  });

  addBall(int color) {
    Ball? ball = getBall(balls, color);
    if (ball != null) {
      ball.count++;
      return ball.count;
    } else {
      balls.add(Ball(color: color, count: 1));
      return 1;
    }
  }

  //to String

}

getBall(List<Ball> previousBalls, int myNewBallColor) {
  for (Ball ball in previousBalls) {
    if (ball.color == myNewBallColor) {
      return ball;
    }
  }
}

class Ball {
  int color;
  int count;
  Ball({
    required this.color,
    required this.count,
  });

}

```
['Dart']