상세 컨텐츠

본문 제목

개인정보 수집 유효기간 (2023 KAKAO BLIND RECRUITMENT)

프로그래머스 코딩테스트 풀이

by 발발개발 2023. 4. 28. 14:49

본문

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

풀이

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

class Solution {
    public Integer[] solution(String today, String[] terms, String[] privacies) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
        Map<String, Integer> termsMap = new HashMap<>();

        for (String term : terms) {
            String[] temp = term.split(" ");

            termsMap.put(temp[0], Integer.parseInt(temp[1]));
        }

        LocalDate now = LocalDate.parse(today, dateTimeFormatter);
        List<Integer> answer = new ArrayList<>();

        for (int i = 0; i < privacies.length; i++) {
            String[] temp = privacies[i].split(" ");

            LocalDate privacyDateTime = LocalDate.parse(temp[0], dateTimeFormatter).plusMonths(termsMap.get(temp[1]));

            if (now.isAfter(privacyDateTime) || now.isEqual(privacyDateTime)) {
                answer.add(i + 1);
            }
        }

        return answer.toArray(new Integer[0]);
    }
}

관련글 더보기

댓글 영역