[Codility] Lession 3.2 FrogJmp

Swift Solution:

public func solution(X : Int, _ Y : Int, _ D : Int) -> Int {
    // Make sure the Destination is far than start point 
    if (Y - X <= 0) { return 0 }

    var steps = (Y - X) / D
 
    if ((Y - X) % D) > 0 { steps += 1 }
    
    return steps

}

你可能感兴趣的:([Codility] Lession 3.2 FrogJmp)