로딩
요청 처리 중입니다...

JAVA_프로그래머스_탐욕법_Greedy_체육복

 JAVA_프로그래머스_탐욕법_Greedy_체육복

JAVA_프로그래머스_탐욕법_Greedy_체육복 풀이 class Solution { public int solution(int n, int[] lost, int[] reserve) { int[] clothes = new int[n + 2]; // 현 인덱스 기준 앞, 뒤 인덱스 값을 처리하기 위해 크기를 n + 2로 지정 for(int i = 1; i <= n; i++) clothes[i] = 1; for(int i : lost) clothes[i]--; for(int i : reserve) clothes[i]++; // 현 인덱스 기준 실행 for(int i = 1; i <= n; i++){ if(clothes[i] == 0){ if(clothes[i - 1] == 2){ clothes[i - 1]--; clothes[i]++; }else if (clothes[i + 1] == 2){ clothes[i + 1]--; clothes[i]++; } } } int count = 0; f...