알고리즘/백준

[python] 백준 1269번 대칭 차집합

펄찌 2022. 2. 4. 23:32

문제 풀이

집합 같은 경우 set() 함수를 이용하면 쉽게 풀 수 있다. 

set() 함수는 중복을 허용하지 않으므로 수식으로 나타내 보면 아래의 수식처럼 나타낼 수 있다.

A U B - (A ∩ B)

합집합 같은경우 union 함수, 교집합 같은 경우 intersection 함수를 사용하면 된다.

 

완성된 코드!!👍😊

n, m = map(int, input().split())
A = set(map(int, input().split()))
B = set(map(int, input().split()))
print(len(A.union(B) - A.intersection(B)))