알고리즘문제중
Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
이때 set을 이용하여
for (int i = 0; i < n; i++) { temp = sc.nextInt(); if(set.contains(temp)) { set.remove(temp); }else { set.add(temp); } }contains 를 이용하여 체크를 할수 있겠지만
add() 메소드 자체적으로 boolean값을 반환한다.
고로..
if ( !set.add(num) ) set.remove(num);
이렇게 나타낼 수 있다.
'Old Posts > Java' 카테고리의 다른 글
| 람다 (0) | 2018.01.11 |
|---|---|
| LinkedList (0) | 2018.01.11 |
| 예외처리 (0) | 2018.01.07 |
| 여러개의 숫자 중 Max,Min 구하기 (0) | 2018.01.07 |
| Scanner / BufferedReader 차이 (0) | 2017.10.21 |