Day67

강태훈·2026년 4월 7일

nbcamp TIL

목록 보기
67/97

알고리즘 코드카타

Replace Employee ID With The Unique Identifier

select ifnull(b.unique_id, null) as unique_id, a.name
from Employees a
left join EmployeeUNI b
on a.id = b.id
;

Product Sales Analysis I

select b.product_name, a.year, a.price
from Sales a
left join Product b
on a.product_id = b.product_id 
;

명예의 전당(1)

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

class Solution {
    public int[] solution(int k, int[] score) {
        List<Integer> list = new ArrayList<>();
        List<Integer> ans = new ArrayList<>();

        for (int i = 0; i < score.length; i++) {
            list.add(score[i]);
            Collections.sort(list, Collections.reverseOrder());
            
            if (i >= k) {
                ans.add(list.get(k - 1));
            } else {
                ans.add(list.get(i));
            }
        }
        return ans.stream().mapToInt(Integer::intValue).toArray();
    }
}

2016년

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

class Solution {
    public String solution(int a, int b) throws ParseException {
        String answer = "-";
        String one = "2016/01/01";
        String date = "2016/" + a + "/" + b;
        Date format1 = new SimpleDateFormat("yyyy/MM/dd").parse(one);
        Date format2 = new SimpleDateFormat("yyyy/MM/dd").parse(date);

        long diffDays = (format2.getTime() - format1.getTime()) / (24*60*60*1000); //일자수 차이

        return answer = switch ((int) (diffDays % 7)) {
            case 0 -> "FRI";
            case 1 -> "SAT";
            case 2 -> "SUN";
            case 3 -> "MON";
            case 4 -> "TUE";
            case 5 -> "WED";
            case 6 -> "THU";
            default -> "wrong";
        };
    }
}

0개의 댓글