[알고리즘]-개인정보 수집 유효기간

dev_woo·2025년 1월 2일
post-thumbnail

요약

풀이시간 : 42분 12초

문제 풀이
1. 1달을 28일로 계산
2. 만료일이 되는 순간 파기
3. split() 메서드의 활용

주의점
1. 타입 변환

고민
1. 변수명 짓기 참 어렵다
2. 시간이 걸려도 천천히 문제 읽기 (실수 줄이는게 관건)
3. 결국 알고리즘 문제는 1.데이터 전처리, 2.계산, 3.결과반환순임 각 파트 명확히하기

문제

[프로그래머스]개인정보 수집 유효기간

풀이

// today : 오늘일짜, term : 약관-유효기간, privacies : 수집일자 - 약관종류
// 1달 28일 기준, 유효기간이 지난 약관 폐기
function solution(today, terms, privacies) {
    const result = []; // 파기대상
    
    const [yearT, monthT, dayT] = today.split(".").map(Number); 
    const totalDaysT = yearT * 12 * 28 + monthT * 28 + dayT;  // 오늘 날짜를 일단위로 변환 -> 1달은 28일
    
    const termMap = new Map(terms.map(term => {// 약관 정보
        const [type, duration] = term.split(" ")
        return [type, Number(duration) * 28];
    }));
    
    for(const [i, privacy] of privacies.entries()){ // 개인정보를 순회하며 파기 여부 파악
        const order = i + 1;
        const [date, termType] = privacy.split(" ");
        const [year, month, day] = date.split(".").map(Number);
                                                   
        const totalDaysP = year * 12 * 28 + month * 28 + day; // 계약일
        const expireDay = totalDaysP + termMap.get(termType); // 만료일 

		// 만료 판단 여부
      	expireDay <= totalDaysT && result.push(order);
    }
    return result;
}
profile
꾸준히 한걸음씩

0개의 댓글