-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/
π¬Β Idea
- λλ¬νλ €λ μμΉμμ μΆλ° μμΉλ₯Ό λΊ κ±°λ¦¬λ₯Ό κ°κ΅¬λ¦¬μ μ ν νμλ‘ λλμ΄ μ ν νμλ₯Ό ꡬνλ€.
- μ΄ λ λλ¨Έμ§κ° λ°μνλ κ²½μ° + 1μ νμ¬ λλ¬νλ €λ μμΉλ₯Ό λμ μ μλλ‘ ν΄μ€λ€.
π¬Β νμ΄
import Foundation
public func solution(X : Int, Y : Int, D : Int) -> Int {
let jmp = (Y - X) / D
return (Y - X) % D != 0 ? jmp + 1 : jmp
}
μμμκ°
: 7λΆ
μκ° λ³΅μ‘λ
: O(1)
νκ°ν
: https://app.codility.com/demo/results/trainingPYHF59-6U5/