[Codility] FrogJmp

Lesson 3 - Time Complexity : FrogJmp

kotlin

ceil() 사용

1
2
3
4
5
import kotlin.math.*

fun solution(X: Int, Y: Int, D: Int): Int {
return ceil((Y - X) / D.toDouble()).toInt()
}

ceil() 사용하지 않고 풀기

1
2
3
4
5
6
7
8
9
10
fun solution(X: Int, Y: Int, D: Int): Int {
if (X == Y) return 0

val quotient = (Y - X) / D

if (X + D * quotient < Y) return quotient + 1
else return quotient

return -1
}

댓글