import java.time.LocalDate
import java.time.format.DateTimeFormatter
class Solution {
fun solution(today: String, terms: Array<String>, privacies: Array<String>): IntArray {
val answer = ArrayList<Int>()
val todayFormattedDate = LocalDate.parse(today, DateTimeFormatter.ofPattern("yyyy.MM.dd"))
val termMap = terms.associate { it.split(" ").let { (code, term) ->
code to term.toInt()
} }
privacies.forEachIndexed { index, privacy ->
privacy.split(" ").let { (startDate, term) ->
val startFormattedDate = LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy.MM.dd"))
val expiredFormattedDate = startFormattedDate.plusMonths(termMap[term]!!.toLong())
if (!expiredFormattedDate.isAfter(todayFormattedDate)) {
answer.add(index + 1)
}
}
}
return answer.toIntArray()
}
}
class Solution1 {
fun solution(today: String, terms: Array<String>, privacies: Array<String>) = privacies.indices.filter { privacies[it].split(" ").first().split("\\.".toRegex()).map(String::toInt).let { (y, m, d) -> (y * 12 * 28) + (m * 28) + d } + (terms.map { it.split(" ") }.associate { (a, b) -> a to b.toInt() }.getOrDefault(privacies[it].split(" ").last(), 0) * 28) <= today.split("\\.".toRegex()).map(String::toInt).let { (y, m, d) -> (y * 12 * 28) + (m * 28) + d } }.map { it + 1 }
}
날짜를 LocalDate로 변환해서 비교함.
Solution1 은 좀 변태같아서 가져와봄