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

shsh·2022년 5월 13일
0

프로그래머스

목록 보기
16/17

https://programmers.co.kr/learn/courses/30/lessons/42576

Dictionary - 성공

from collections import Counter

def solution(participant, completion):
    pCnt = Counter(participant)
    cCnt = Counter(completion)
    for p, v in pCnt.items():
        if p not in cCnt or cCnt[p] != v:
            return p

참가자 이름별 숫자와 완주자 이름별 숫자를 Counter 로 구함
두 값을 비교하며 완주자가 아니거나 같은 이름의 완주한 사람 수와 참가한 사람 수가 다르면 return

그 외

  • collections.Counter(participant) - collections.Counter(completion) 가능
  • 두 리스트 모두 정렬 후, 비교
  • Hash 값 합의 차 hash(p)
profile
Hello, World!

0개의 댓글