Update 04_recursive_max.kt (#266)

add an argument to when block
This commit is contained in:
Adnan
2023-08-09 02:40:53 +03:30
committed by GitHub
parent 3e99cccfc0
commit 8969269a10

View File

@@ -1,5 +1,5 @@
private fun max(list: IntArray): Int = when {
list.size == 2 -> if (list[0] > list[1]) list[0] else list[1]
private fun max(list: IntArray): Int = when (list.size) {
2 -> if (list[0] > list[1]) list[0] else list[1]
else -> {
val subMax = max(list.copyOfRange(1, list.size))
if (list[0] > subMax) list[0] else subMax