TLI/코드카타
2024.06.03 TIL 코트카타 71번(개인정보 수집 유효기간)
jaeseonyoo
2024. 6. 3. 20:57
fun solution(today: String, terms: Array<String>, privacies: Array<String>): IntArray {
var answer = mutableListOf<Int>()
var termToExpiration = mutableMapOf<String, Int>()
for(term in terms) {
val splitedTerm = term.split(" ")
termToExpiration.put(splitedTerm[0], splitedTerm[1].toInt())
}
val todayToAmount = calculateDateToAmount(today)
for(privacyIndex in privacies.indices) {
val splitedPrivacy = privacies[privacyIndex].split(" ")
val calculatedDateAmount = calculateDateToAmount(splitedPrivacy[0]) + termToExpiration.get(splitedPrivacy[1])!! * 28
if(todayToAmount >= calculatedDateAmount)
answer.add(privacyIndex+1)
}
return answer.toIntArray()
}
fun calculateDateToAmount(dateString: String): Int {
val splitedDate = dateString.split(".")
return (splitedDate[0].toInt() * 12*28) + (splitedDate[1].toInt() * 28) + splitedDate[2].toInt()
}
풀이 과정
- 연-월-일로 되어있는 날짜를 일로 환산한다.
- 일로 환산된 개인정보 수집일자 + 유효기간과 현재 날짜를 비교한다.
- 현자날짜가 더 크거나 같으면 만료된 것으로 간주한다.
포인트
- 연-월-일을 일로 환산
- (연 * 12 * 28) + (월 * 12) + 일