💡 풀이
- String 날짜를 일수로 변경해주는 함수 => toDays
- 약관 종류와 유효기간 Map에 담기
- privacies 하나씩 확인하면서 개인정보 수집 일자 + 유효기간 일수 구하기
- 오늘 날짜 일수와 비교해서 오늘 날짜가 더 크면 만료기간이 지났으므로 정답 리스트에 담기
- ⭐ "2021.01.11" . 기준으로 나눌 때 split(".") 아닌 split("\.")으로 해야함
-> 전자로 하면 .(dot)을 모든 문자를 기준으로 나뉨
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
int todays = toDays(today);
ArrayList<Integer> res = new ArrayList<>();
HashMap<String, Integer> termMap = new HashMap<>();
for(String term : terms){
termMap.put(term.split(" ")[0], Integer.parseInt(term.split(" ")[1]));
}
for(int i = 0; i<privacies.length; i++){
String[] sp = privacies[i].split(" ");
int expDays = toDays(sp[0]) + termMap.get(sp[1]) * 28;
if (todays >= expDays) res.add(i+1);
}
int[] answer = new int[res.size()];
int idx = 0;
for(int r : res){
answer[idx++] = r;
}
return answer;
}
public int toDays(String date){
String[] d = date.split("\\.");
int year = Integer.parseInt(d[0]);
int month = Integer.parseInt(d[1]);
int day = Integer.parseInt(d[2]);
return year * 12 * 28 + month * 28 + day;
}
}