작은하마

[codility] FrogJmp 본문

코딩테스트/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)

'코딩테스트 > Codility' 카테고리의 다른 글

[Codility] PermCheck  (0) 2021.07.29
[Codility] 짝지어 제거하기  (0) 2021.07.26
[Codility] odd occurrences in array  (0) 2021.07.23
[codility]디버깅문제  (0) 2021.07.22
[codility] 합이 같은 수  (0) 2021.07.22
Comments