알고리즘
프로그래머스 level1 : 개인정보 수집 유효기간 - Java
mezo
2023. 6. 2. 11:07
728x90
반응형
import java.util.*;
import java.lang.Math;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
List<Integer> answer = new ArrayList<>();
Map<String, Integer> termMap = new HashMap<>();
int day = getDate(today);
for(String term : terms){
String[] t = term.split(" ");
termMap.put(t[0], Integer.parseInt(t[1]));
}
for(int i = 0; i < privacies.length; i++){
String[] p = privacies[i].split(" ");
int endDay = getDate(p[0]) + termMap.get(p[1]) * 28 - 1;
if(day > endDay) {answer.add(i+1); }
}
return answer.stream().mapToInt(i -> i).toArray();
}
public int getDate(String today){
System.out.println(today);
String[] date = today.split("\\.");
int year = Integer.parseInt(date[0]) * 28 * 12;
int month = Integer.parseInt(date[1]) * 28;
int day = Integer.parseInt(date[2]);
return year + month + day;
}
}
728x90
반응형