Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 러닝일지
- COS PRO
- db
- 건강
- greedy
- 코테
- 자바
- BOJ
- 문제해결
- binary search
- 코딩테스트
- math
- 투포인터
- 알고리즘
- SWEA
- 프로그래머스
- MySQL
- DP
- oracle
- 백준
- Java
- priorityqueue
- 운동기록
- 문자열
- dfs
- BFS
- 이분탐색
- SQL
- 시뮬레이션
- 문제풀이
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.1 체육복 본문


[문제]
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
HashSet<Integer> lost_hs = new HashSet<>();
HashSet<Integer> reserve_hs = new HashSet<>();
for(int i : lost) lost_hs.add(i);
for(int i : reserve) {
if(lost_hs.contains(i)){
lost_hs.remove(i);
}
else reserve_hs.add(i);
}
for(int i : reserve_hs){
if(lost_hs.contains(i-1)){
lost_hs.remove(i-1);
}
else if(lost_hs.contains(i+1)){
lost_hs.remove(i+1);
}
}
int answer = n - lost_hs.size();
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.3 입국 심사 (0) | 2025.10.09 |
|---|---|
| [프로그래머스] Lv.1 예산 (0) | 2025.10.09 |
| [프로그래머스] Lv.1 모의 고사 (0) | 2025.10.09 |
| [프로그래머스] Lv.2 소수 찾기 (0) | 2025.10.09 |
| [프로그래머스] Lv.2 가장 큰 수 (0) | 2025.10.08 |