코딩테스트

[코딩테스트(Java)] 프로그래머스 150370 개인정보 수집 유효기간

inhooo00 2025. 3. 17. 02:49

https://school.programmers.co.kr/learn/courses/30/lessons/150370

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

public int[] solution(String today, String[] terms, String[] privacies) {
    List<Integer> answer = new ArrayList<>();

    String[] strings = today.split("\\.");
    int todaySum =
            Integer.parseInt(strings[0]) * 12 * 28 + Integer.parseInt(strings[1]) * 28 + Integer.parseInt(
                    strings[2]);

    Map<String, Integer> mapTerms = new HashMap<>();
    for (int i = 0; i < terms.length; i++) {
        String[] string = terms[i].split(" ");
        mapTerms.put(string[0], Integer.parseInt(string[1]) * 28);
    }

    for (int i = 0; i < privacies.length; i++) {
        String[] string = privacies[i].split(" ");
        String[] integers = string[0].split("\\.");
        int sum =
                Integer.parseInt(integers[0]) * 12 * 28 + Integer.parseInt(integers[1]) * 28 + Integer.parseInt(
                        integers[2]);

        if (sum + mapTerms.get(string[1]) <= todaySum) {
            answer.add(i + 1);
        }
    }

    Collections.sort(answer);
    int[] arr = answer.stream()
            .mapToInt(Integer::intValue)
            .toArray();

    return arr;
}

 

 

 

📍포인트

1. 날짜 계산을 어떻게할지 판단하기
2. map 사용.
3. List to Array

 

 

 

📍삽질

1. 처음 코드는 쓸모없는 map을 하나 더 만들어서 순서가 보장되지 않게되어 추가되는 배열이 이상했음.
2. List to Array 방법이 기억이 안 났음.