코딩테스트/Codility
[codility] FrogJmp
꼬몽울
2021. 7. 23. 18:37
https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/
FrogJmp coding task - Learn to Code - Codility
Count minimal number of jumps from position X to Y.
app.codility.com
처음에 while문으로 했지만 시간복잡도가 0점이 나왔다..
count=0
while True:
x+=d
count+=1
if x>=y:
break
count
그래서 아래것으로 바꾸어 풀어보았다.
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(X, Y, D):
# write your code in Python 3.6
return math.ceil((Y-X)/D)