class Solution {
fun solution(num_list: IntArray): Int {
var odd = 0
var even = 0
odd = num_list.filter{ it % 2 != 0}.joinToString("").toInt()
even = num_list.filter{ it % 2 == 0}.joinToString("").toInt()
return odd + even
}
}
class Solution {
fun solution(numList: IntArray) = numList.partition { it % 2 == 0 }.toList().sumOf { it.joinToString("").toInt() }
}
filter
val numbers = listOf(1, 2, 3, 4, 5)
val evens = numbers.filter { it % 2 == 0 }
println(evens) // 출력: [2, 4]
joinToString
val names = listOf("Alice", "Bob", "Charlie")
println(names.joinToString(", ", prefix = "[", postfix = "]"))
// 출력: [Alice, Bob, Charlie]
partition
val numbers = listOf(1, 2, 3, 4, 5)
val (evens, odds) = numbers.partition { it % 2 == 0 }
println(evens) // 출력: [2, 4]
println(odds) // 출력: [1, 3, 5]
sumOf
data class Product(val name: String, val price: Double, val quantity: Int)
val products = listOf(
Product("Apple", 1.5, 10),
Product("Banana", 0.8, 20)
)
val totalCost = products.sumOf { it.price * it.quantity }
println(totalCost) // 출력: 31.0