https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr



<풀이 과정>
문제의 핵심은 기간을 비교하면 되는 것이다.
우선 약관종류에 따른 유효기간은 Map에 넣어 사용했고, 모든 비교를 일(days)로 바꿔 계산했다.
<제출 코드>
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
PriorityQueue<Integer> pq = new PriorityQueue<>();
int year = Integer.parseInt(today.split("\\.")[0]);
int month = Integer.parseInt(today.split("\\.")[1]);
int day = Integer.parseInt(today.split("\\.")[2]);
int flag = (year * 12 * 28) + (month * 28) + day;
// 유효기간
HashMap<String, String> map = new HashMap<>();
for(int i=0; i<terms.length; i++){
map.put(terms[i].split(" ")[0], terms[i].split(" ")[1]);
}
// 개인정보 수집 만료일 확인
for(int i=0; i<privacies.length; i++){
String date = privacies[i].split(" ")[0];
int y = Integer.parseInt(date.split("\\.")[0]);
int m = Integer.parseInt(date.split("\\.")[1]);
int d = Integer.parseInt(date.split("\\.")[2]);
String type = privacies[i].split(" ")[1];
int sum = (y * 12 * 28) + (m * 28) + d + (Integer.parseInt(map.get(type)) * 28);
if(flag >= sum) pq.add(i+1);
}
int[] answer = new int[pq.size()];
int idx = 0;
while(!pq.isEmpty()){
answer[idx++] = pq.poll();
}
return answer;
}
}
'코테 > 프로그래머스' 카테고리의 다른 글
99클럽 코테 스터디 8일차 TIL 백트래킹(양과 늑대) (1) | 2025.01.23 |
---|---|
99클럽 코테 스터디 2일차 TIL 트라이(가사 검색) (1) | 2025.01.14 |
99클럽 코테 스터디 33일차 TIL 문자열(신규 아이디 추천) (0) | 2024.11.30 |
99클럽 코테 스터디 24일차 TIL 완전탐색(전력망을 둘로 나누기) (1) | 2024.11.20 |
99클럽 코테 스터디 23일차 TIL 완전탐색(소수찾기) (0) | 2024.11.20 |