
https://school.programmers.co.kr/learn/courses/30/lessons/150370
: 처음엔 약관의 기간이 월 기준이라 Month, year 가 12월이 넘어가면 변경하고, day는 유지하는 식으로 했지만,
그래도 결국엔 변경된 날짜 & 오늘 날짜 를 비교해야 하므로,
datetime을 쓰다가 결국 시간 초과가 났다.
(계산, datetime 쓰기 위해 형변환 많이써서 그런듯..)
각 달의 날짜 수(day)가 동일하면, 날짜 비교 시 가장 빠른 방법은 날짜 수 연산이다.
def solution(today, terms, privacies):
answer = []
dict_term = {}
for term in terms:
k, v = term.split(" ")
dict_term[k] = int(v)
for i, p in enumerate(privacies):
days = 0
date, term = p.split(" ")
yy, mm, dd = map(int,date.split("."))
days += dict_term[term] * 28
days += yy * 12 * 28
days += mm * 28
days += dd
t = list(map(int,today.split(".")))
t_days = t[0]*12*28 + t[1]*28 + t[2]
if days <= t_days:
answer.append(i+1)
return answer