Painless
FrogJmp
Count the minimum number of jumps from position X to Y.
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:
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