Tuesday, May 17, 2016

Codility FrogJmp Solution C#

Codility FrogJmp Solution C# - Count minimal number of jumps from position X to Y.



Solution:


public int solution(int X, int Y, int D)
        {
            int distance = Y - X;
            int div = (distance / D);
            int mod = (distance % D);
            if (mod != 0)
            {
                return div + 1;
            }
            else
            {
                return div;
            }
        }
And Here goes the result, got 100%




No comments:

Post a Comment