[GO] [100%] FrogJmp (src & jUnit)

Painless

FrogJmp

Count the minimum number of jumps from position X to Y. image.png

Task description

A little frog wants to go to the other side of the road. The frog is currently in position X and wants to reach a position above Y. The little frog always jumps a certain distance D.

Count the minimum number of jumps a small frog must make to reach its goal.

Write a function:

class Solution {public int solution(int X、int Y、int D); }

It returns the minimum number of jumps from position X to positions above Y, given the three integers X, Y, and D.

For example:

   X = 10
   Y = 85
   D = 30

The function should return 3 because the frog is placed like this:

Write a ** efficient ** algorithm for the following assumptions:


solve

Program FrogJmpSolution.java

FrogJmpSolution.java


    public int solution(int X, int Y, int D) {
        return (int) Math.ceil ((double) (Y - X) / D);
    }

Detected time complexity:
O(1)

jUnit FrogJmpSolutionTest.java

Report Candidate Report: trainingBFBAZF-EXF


Recommended Posts

[100%] FrogJmp (src & jUnit)
[100%] CyclicRotation (src & jUnit)
[100%] PermMissingElem (src & jUnit)
[100%] FrogRiverOne (src & jUnit)
[100%] OddOccurrencesInArray (src & jUnit)
[100%] MinAvgTwoSlice (src & junit)
[100%] PassingCars (src & junit)
[100%] PermCheck (src & junit)
[100%] TapeEquilibrium (src & jUnit)
[100%] MaxProductOfThree (src & jUnit)
[100%] BinaryGap (src & jUnit)
[100%] MissingInteger (src & junit & author's note)
[100%] [GenomicRangeQuery] (src & junit & author's note)
[100%] MaxCounters (src & junit & author's note)
[100%] Distinct (src & junit & author's note)
[100%] CountDiv (src & junit & author's note)
junit
JUnit 4 notes
JUnit story
JUnit memorandum