https://school.programmers.co.kr/learn/courses/30/lessons/150370
풀이
이러한 Date처리 문자열문제인데 Date타입을 잘 안다뤄봐서 전부 String으로 잘라서 풀었다.. 여러분은 나처럼 무식하게 풀지 마시길..
PS) 잘못된 풀이인줄 알았는데 찾아보니 사람들 대부분 이렇게 풀었다..
import java.util.*;
class Solution {
public ArrayList solution(String today, String[] terms, String[] privacies) {
int tYear = Integer.parseInt(today.substring(0,4));
int tMonth = Integer.parseInt(today.substring(5,7));
int tDay = Integer.parseInt(today.substring(8,10));
Hashtable<String,Integer> privaciestable = new Hashtable<>();
for(String p: terms){
privaciestable.put(p.substring(0,1),Integer.parseInt(p.substring(2,p.length())));
}
ArrayList<Integer> overprivacy = new ArrayList<>();
for(int i=0; i<privacies.length; i++){
int pYear = Integer.parseInt(privacies[i].substring(0,4));
int pMonth = Integer.parseInt(privacies[i].substring(5,7));
int pDay = Integer.parseInt(privacies[i].substring(8,10));
String pType = privacies[i].substring(11,12);
int overDate = 0;
int overY = (tYear - pYear) * 12 ;
int overM = (tMonth - pMonth) ;
overDate+= overY + overM;
if(tDay - pDay < 0){
overDate -= 1;
}
if(overDate >= privaciestable.get(pType)){
int num = i+1;
overprivacy.add(num);
}
}
return overprivacy;
}
}
일단은 정답
개인적으로 좋아보이는 풀이들
https://rovictory.tistory.com/172
댓글