개인정보 수집 유효기간

seheeee_97·2024년 1월 3일
0

회고팀

목록 보기
39/41






import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

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

        // 오늘 날짜를 LocalDate로 변환
        LocalDate todayDate = LocalDate.parse(today, DateTimeFormatter.ofPattern("yyyy.MM.dd"));

        for (int i = 0; i < terms.length; i++) {
            // 약관별 유효기간에서 숫자만 추출하여 정수로 변환
            int term = Integer.parseInt(terms[i].replaceAll("[^0-9]", "").trim());

            // 개인정보 수집 일자를 LocalDate로 변환
            LocalDate privacyDate = LocalDate.parse(privacies[i].split(" ")[0], DateTimeFormatter.ofPattern("yyyy.MM.dd"));

            // 유효기간 계산
            LocalDate expirationDate = privacyDate.plusMonths(term);

            // 오늘 날짜와 비교하여 유효기간이 지났다면 toBeDestroyed 리스트에 추가
            if (todayDate.isAfter(expirationDate)) {
                toBeDestroyed.add(i + 1); // 개인정보 번호는 1부터 시작하므로 i + 1을 추가
            }
        }

        // 리스트를 배열로 변환
        int[] answer = new int[toBeDestroyed.size()];
        for (int i = 0; i < answer.length; i++) {
            answer[i] = toBeDestroyed.get(i);
        }

        return answer;
    }
}









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

0개의 댓글