1016번 : 숫자 카드2

김민관·2022년 9월 24일

백준_Silver

목록 보기
48/57

문제

파이썬

answer = {}
n = int(input())

cards = list(map(int, input().split()))
cards.sort()

m = int(input())
nums = list(map(int, input().split()))

for i in cards:
    if i not in answer:
        answer[i] = 1
    else:
        answer[i] += 1

for i in nums:
    result = answer.get(i)
    if result:
        print(answer[i], end=' ')
    else:
        print(0, end=' ')

풀이

  • 숫자 카드1에서 이분탐색으로 풀었던 내용에 해쉬를 사용하여 푸는 해결법도 있지만 해쉬만으로도 끝낼수 있어서 이분탐색을 쓰지않음
  • 속도 면에서도 해쉬만 사용하는 것이 훨씬 빠름
profile
게임 개발일지 & IT 소식들 공유

0개의 댓글