Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- C
- 데이터베이스
- 갭체크
- 코드트리
- 오블완
- 1일1코테
- 웹
- 알고리즘
- 파이썬
- 개발자취업
- 코테공부
- 99클럽
- 자바스크립트
- 자바
- 코딩테스트준비
- 플로이드-워셜
- 연결 리스트
- 프로그래밍 언어
- Java
- 코딩테스트
- 코딩테스트사이트추천
- 프로그래머스
- 개발자루틴
- 항해99
- 운영체제
- #코드트리 #코딩테스트 #코테공부 #백트래킹 #알고리즘 기초
- 티스토리챌린지
- 자료구조
- 인접 행렬
- til
Archives
- Today
- Total
와드의 블로그
99클럽 코테 스터디 34일차 TIL 본문
미들러
문제
개인정보 수집 유효기간
#문자열
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
풀이
개인정보 수집 일자와 오늘 날짜가 주어졌을 때 약관에 따라 폐기되어야 하는 개인정보를 반환하는 문제이다.
약관 종류에 따라 유효기간이 정해지므로 이를 맵으로 관리한다.
개인정보 수집일자에 유효기간을 더했을 때 오늘날짜보다 이전이라면 해당 개인정보는 폐기해야한다.
코드
import java.util.*;
class Solution {
HashMap<String, Integer> mp = new HashMap<>();
boolean check(String a, String b, int c) {
int y1 = Integer.parseInt(a.substring(0, 4));
int m1 = Integer.parseInt(a.substring(5, 7));
int d1 = Integer.parseInt(a.substring(8));
int y2 = Integer.parseInt(b.substring(0, 4));
int m2 = Integer.parseInt(b.substring(5, 7));
int d2 = Integer.parseInt(b.substring(8));
m2 += c % 12;
y2 += c / 12;
if (m2 > 12) {
m2 -= 12;
y2++;
}
return y1 > y2 || (y1 == y2 && m1 > m2) || (y1 == y2 && m1 == m2 && d1 >= d2);
}
public int[] solution(String today, String[] terms, String[] privacies) {
for (String s : terms)
mp.put(s.substring(0, 1), Integer.parseInt(s.substring(2)));
ArrayList<Integer> al = new ArrayList<>();
for (int i = 0; i < privacies.length; i++) {
if (check(today, privacies[i].substring(0, 10), mp.get(privacies[i].substring(11))))
al.add(i + 1);
}
int[] ans = new int[al.size()];
int idx = 0;
for (int i : al)
ans[idx++] = i;
return ans;
}
}
'TIL' 카테고리의 다른 글
| [코드트리 후기] 코딩테스트 준비, 갭체크부터 시작하기 (0) | 2026.05.07 |
|---|---|
| 99클럽 코테 스터디 35일차 TIL (0) | 2024.12.01 |
| 99클럽 코테 스터디 33일차 TIL (1) | 2024.11.29 |
| 99클럽 코테 스터디 32일차 TIL (0) | 2024.11.28 |
| 99클럽 코테 스터디 31일차 TIL (0) | 2024.11.27 |