Day77

강태훈·2026년 4월 21일

nbcamp TIL

목록 보기
77/97

알고리즘 코드카타

Project Employees I

select a.project_id, round(avg(b.experience_years),2) as average_years
from Project a
join Employee b
on a.employee_id = b.employee_id
group by a.project_id
;

체육복

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

class Solution {
    public int solution(int n, int[] lost, int[] reserve) {
        int answer = n - lost.length;

        Arrays.sort(lost);
        Arrays.sort(reserve);

        List<Integer> list = new ArrayList<>();
        boolean[] check = new boolean[n+1];
        for(int i: reserve) {
            list.sort(Integer::compareTo);

            int index = Arrays.binarySearch(lost, i);
            int index2 = Collections.binarySearch(list, index);
            if (index >= 0 && index2 < 0) {
                answer++;
                list.add(index);
                check[i] = true; 
            }
        }

        for(int i: reserve){
            list.sort(Integer::compareTo);

            if (check[i]){
                continue;
            }

            if(i != 1){
                int index = Arrays.binarySearch(lost, i-1);
                int index2 = Collections.binarySearch(list, index);
                if(index >= 0 && index2 < 0){
                    answer++;
                    list.add(index);
                    continue;
                }
            }

            if (i != n) {
                int index = Arrays.binarySearch(lost, i+1);
                int index2 = Collections.binarySearch(list, index);
                if(index >= 0 && index2 < 0){
                    answer++;
                    list.add(index);
                    continue;
                }
            }
        }
        return answer;
    }
}

0개의 댓글