-
[프로그래머스] 개인정보 수집 유효기간(Python)Algorithm PS👩🏻💻/프로그래머스 2023. 5. 10. 01:59
문제 링크
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
'Algorithm PS👩🏻💻 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 17680번: 캐시(Python, deque) (1) 2024.04.19 [프로그래머스] 두 정수 사이의 합(Python) (0) 2023.05.23 [프로그래머스] 나누어 떨어지는 숫자 배열(Python) (0) 2023.05.23 [프로그래머스] 기사단원의 무기(Python) (0) 2023.05.10 [프로그래머스] 타켓 넘버(Python) (0) 2023.05.10