- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/150370
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/개인정보 수집 유효기간
풀이 시간 : 1시간 20분
import java.util.*;
class Solution {
public List<Integer> solution(String today, String[] terms, String[] privacies) {
int mDays = 28;
int totalToday = getTotalDays(today, mDays);
List<Integer> answer = new ArrayList<>();
Map<Character, Integer> termMap = new HashMap<>();
for (String term : terms) {
termMap.put(term.charAt(0), Integer.parseInt(term.substring(2)));
}
for (int i = 0; i < privacies.length; i++) {
char pO = privacies[i].charAt(11);
int totalPrivacy = getTotalDays(privacies[i].substring(0, 10), mDays) +
termMap.get(pO) * mDays;
if (totalPrivacy <= totalToday) {
answer.add(i + 1);
}
}
return answer;
}
private int getTotalDays(String date, int mDays) {
String[] parts = date.split("\\.");
return (Integer.parseInt(parts[0]) * mDays * 12) +
(Integer.parseInt(parts[1]) * mDays) +
Integer.parseInt(parts[2]);
}
}