[프로그래머스] 완주하지 못한 선수

박신희·2022년 4월 7일
0
post-thumbnail

🤜 풀이

def solution(participant, completion):
    answer = []
    # { 참가자:count } 형식으로 dictionary 생성 ( 초기값 : 0 )
    cnt=[ 0 for _ in range(len(participant))]
    p_dict=dict(zip(participant,cnt))
    
    # 참가자수 +1 해주기
    for i in participant:
        p_dict[i]+=1
    
    # 참가자수 -1 해주기
    for i in completion:
        p_dict[i]-=1
    
    # 남은 참가자수 (1명인거 찾기) 찾아서 참가자 이름 출력
    for key, value in p_dict.items():
        if value==1:
            return key
profile
log my moments 'u')/

0개의 댓글