풀이
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
ArrayList<Integer> answer = new ArrayList<>();
HashMap<String, Integer> map = new HashMap<>();
int date = getDate(today);
for (String s : terms) {
String[] term = s.split(" ");
map.put(term[0], Integer.parseInt(term[1]));
}
for (int i = 0; i < privacies.length; i++) {
String[] privacy = privacies[i].split(" ");
if (getDate(privacy[0]) + (map.get(privacy[1]) * 28) <= date) {
answer.add(i + 1);
}
}
return answer.stream().mapToInt(integer -> integer).toArray();
}
private int getDate(String today) {
String[] date = today.split("\\.");
int year = Integer.parseInt(date[0]);
int month = Integer.parseInt(date[1]);
int day = Integer.parseInt(date[2]);
return (year * 12 * 28) + (month * 28) + day;
}
}
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
날짜를 다 day 일수로 변경하는 함수를 만들고 일수만 비교로!