[LeetCode] 3222. Find the Winning Player in Coin Game

Chobby·2026년 1월 2일

LeetCode

목록 보기
875/981
post-thumbnail

😎풀이

  1. 현재 플레이어를 기록
  2. 115 코인을 만들 수 있는 경우 반복
    2-1. 잔여 코인 중 필요 코인 차감
    2-2. 다음 플레이어 차례 갱신
  3. 115 코인을 맞추지 못한 경우, 상대방 우승
function winningPlayer(x: number, y: number): string {
    const PLAYER = ['Alice', 'Bob']
    let isAliceTurn = true
    while(x >= 1 && y >= 4) {
        x -= 1
        y -= 4
        isAliceTurn = !isAliceTurn
    }
    return isAliceTurn ? 'Bob' : 'Alice'
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글