-
[2024 KAKAO WINTER INTERNSHIP] n + 1 카드게임코딩 테스트/Level 3 2024. 12. 18. 13:07반응형
https://school.programmers.co.kr/learn/courses/30/lessons/258707#
def solution(coin, cards): def check(deck1, deck2): for card in deck1: if (order_card := target - card) in deck2: deck1.remove(card) deck2.remove(order_card) return True return False target = len(cards) + 1 hand_size = len(cards) // 3 hand = set(cards[:hand_size]) pending = set() deck = cards[hand_size:][::-1] turn = 1 while coin >= 0 and deck: pending.add(deck.pop()) pending.add(deck.pop()) if check(hand, hand): pass elif coin >= 1 and check(hand, pending): coin -= 1 elif coin >= 2 and check(pending, pending): coin -= 2 else: break turn += 1 return turn
반응형