2014年4月19日土曜日

Lesson 1: FrogJmp (Frog Jmp)

https://codility.com/programmers/lessons/
Lesson 1 - FrogJmpの答えがこちらになります。これは簡単。

====================================================
Complexity:

expected worst-case time complexity is O(1);
expected worst-case space complexity is O(1).
====================================================







int solution(int X, int Y, int D) {
    int distance = Y - X;
    return distance % D == 0 ? distance / D : distance / D + 1;
}

0 件のコメント:

コメントを投稿