[백준] 1764번 듣보잡

거북이·2023년 1월 11일
0

백준[실버4]

목록 보기
16/91
post-thumbnail

💡문제접근

  • 집합 자료형을 이용해서 교집합을 출력하는 intersection을 활용했다.
  • intersection을 이용해서 편하게 코드를 작성했지만 시간이 많이 소요되어 별로 좋지 못한 코드라고 생각된다. 시간 문제를 해결할 수 있는 코드를 공부해봐야겠다.

💡코드(메모리 : 43448KB, 시간 : 4916ms)

N, M = map(int, input().split())

not_hear = set()
for _ in range(N):
    not_hear.add(input())

not_see = set()
for _ in range(M):
    not_see.add(input())

intersection = not_see.intersection(not_hear)
intersection = sorted(intersection)
print(len(intersection))
for i in intersection:
    print(i)

💡소요시간 : 3m

0개의 댓글