시뮬레이션
https://school.programmers.co.kr/learn/courses/30/lessons/150370
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
Map<String, Integer> termMap = new HashMap<>();
for(String term : terms) {
String[] split = term.split(" ");
termMap.put(split[0], Integer.parseInt(split[1]) * 28);
}
List<PersonalInfo> personalInfos = new ArrayList<>();
for(String privacy : privacies) {
String[] split = privacy.split(" ");
int collectedDays = dateToDays(split[0]);
String type = split[1];
personalInfos.add(new PersonalInfo(collectedDays, type));
}
int todayDays = dateToDays(today);
List<Integer> ansList = new ArrayList<>();
for(int i=0; i<personalInfos.size(); i++) {
PersonalInfo personalInfo = personalInfos.get(i);
int expireDays = termMap.get(personalInfo.type);
if(personalInfo.collectedDays + expireDays <= todayDays) {
ansList.add(i + 1);
}
}
return ansList.stream().mapToInt(Integer::intValue).toArray();
}
public int dateToDays(String date) {
String[] split = date.split("\\.");
int year = Integer.parseInt(split[0]);
int month = Integer.parseInt(split[1]);
int day = Integer.parseInt(split[2]);
return day + month * 28 + year * 12 * 28;
}
static class PersonalInfo {
int collectedDays; // day 환산
String type;
public PersonalInfo(int collectedDays, String type) {
this.collectedDays = collectedDays;
this.type = type;
}
}
}
public int dateToDays(String date) {
String[] split = date.split("\\.");
int year = Integer.parseInt(split[0]);
int month = Integer.parseInt(split[1]);
int day = Integer.parseInt(split[2]);
return day + month * 28 + year * 12 * 28;
}
List<Integer> ansList = new ArrayList<>();
for(int i=0; i<personalInfos.size(); i++) {
PersonalInfo personalInfo = personalInfos.get(i);
int expireDays = termMap.get(personalInfo.type);
if(personalInfo.collectedDays + expireDays <= todayDays) {
ansList.add(i + 1);
}
}
30분