유효기간을 체크해 해당 번호를 출력하는 문제이다.
def solution(today, terms, privacies):
answer = []
today = today.split('.')
today = int(today[0])*12*28 + int(today[1])*28 +int(today[2])
terms = { term.split()[0]:int(term.split()[1])*28 for term in terms}
for i, privacy in enumerate(privacies):
day,term = privacy.split()
day = day.split('.')
day = int(day[0])*12*28 + int(day[1])*28 +int(day[2])
day += terms[term]
if(today >= day):
answer.append(i+1)
return answer
이분은 split를 안쓰고 리스트컴프리핸스와 if문을 사용해서 간단히 줄였다.
def to_days(date):
year, month, day = map(int, date.split("."))
return year * 28 * 12 + month * 28 + day
def solution(today, terms, privacies):
months = {v[0]: int(v[2:]) * 28 for v in terms}
today = to_days(today)
expire = [
i + 1 for i, privacy in enumerate(privacies)
if to_days(privacy[:-2]) + months[privacy[-1]] <= today
]
return expire'코딩테스트' 카테고리의 다른 글
| 2025 프로그래머스 코드챌린지 2차 예선완전범죄 (1) | 2025.05.31 |
|---|---|
| 2022 KAKAO BLIND RECRUITMENT신고 결과 받기 (0) | 2025.05.31 |
| 2024 KAKAO WINTER INTERNSHIP 가장 많이 받은 선물 (0) | 2025.05.30 |
| 프로그래머스 택배상자 389478 (1) | 2025.05.29 |
| 프로그래머스 석유시추 (0) | 2024.06.26 |