ProgramSoliving
프로그래머스 : 체육복
하이후에호
2020. 12. 23. 02:15
반응형
import java.util.*;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int check[] = new int[32];
for(int r : reserve){
check[r]++;
}
for(int l : lost){
check[l]--;
}
int answer = 0;
for(int i=1;i<=n;i++){
if(check[i]>=0){
answer++;
}else if(check[i]==-1){
if(check[i-1]==1){
check[i-1]--;
answer++;
}else if(check[i+1]==1){
check[i+1]--;
answer++;
}
}
}
return answer;
}
}반응형