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

앙이🐯·2022년 6월 24일
0

알고리즘

목록 보기
19/22

백준 1269번: 대칭 차집합

1. 문제 설명

2. 문제 풀이

HashSet<데이터타입> 변수명 = new HashSet<데이터타입>(); 
HashSet<Integer> : Integer형의 HashMap 데이터
HashSet<String> : String형의 HashMap 데이터

HashSet의 특정 값이 있나 확인 시 contains(value) 메소드를 사용
값이 존재한다면 true, 값이 없다면 false를 return

HashSet<Integer> A = new HashSet<>();
A.contains(b)
코드
import java.util.*;

public class No_1269 {
	public static void main(String[] args) {
		
		Scanner sc= new Scanner(System.in);
		
		int count=0;
		
		int acnt=sc.nextInt();
		int bcnt=sc.nextInt();
		
		HashSet<Integer> A = new HashSet<>();
		HashSet<Integer> B = new HashSet<>();
		
		for(int i=0;i<acnt;i++) {
			A.add(sc.nextInt());
		}
		
		for(int i=0;i<bcnt;i++) {
			B.add(sc.nextInt());
		}
		
		for(Integer b:B) {
			if(!A.contains(b))
				count++;
		}
		
		for(Integer a:A) {
			if(!B.contains(a))
				count++;
		}
		
		System.out.println(count);
		
	}

}
결과

0개의 댓글