[LeetCode] 3238. Find the Number of Winning Players

Chobby·2026년 1월 2일

LeetCode

목록 보기
878/1063

😎풀이

  1. pick 순회
    1-1. 현재 플레이어가 뽑은 공 색 누적
    1-2. 만약, 동일한 색상의 공을 현재 플레이어 번호 + 1만큼 뽑은 경우 승자로 간주
  2. 승자의 수 반환
function winningPlayerCount(n: number, pick: number[][]): number {
    const winner = new Set<number>()
    const history = new Map<string, number>()
    for(const [player, color] of pick) {
        if(winner.has(player)) continue
        const curKey = player + ', ' + color
        const curValue = (history.get(curKey) ?? 0) + 1
        history.set(curKey, curValue)
        if(curValue > player) winner.add(player)
    }
    return winner.size
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글