2014年4月19日土曜日

Lesson 1: FrogJmp (Frog Jmp)


This one is quite easy.
====================================================
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 件のコメント:

コメントを投稿