Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution { public int solution(int X, int Y, int D); }
- Assume that:
- X, Y and D are integers within the range [1..1,000,000,000];
- X ≤ Y.
- Complexity:
- expected worst-case time complexity is O(1);
- expected worst-case space complexity is O(1).
- class Solution {
- //X=start, Y=end, D=distance for code clarity
- public int solution(int start, int end, int distance) {
- // write your code in Java SE 7
- int progress = start;
- int count=0;
- while(progress<end) {
- progress=progress+distance;
- count++;
- }
- return count;
- }
- }
- public class Frog {
- public static int solution(int x, int y, int d) {
- return (int) Math.ceil((y - x) / (float)d);
- }
- if ((y - x) % d == 0) {
- return (y - x) / d;
- }
- return (y - x) / d + 1;
- return (y - x) / d + ((y - x) % d == 0 ? 0 : 1);
- class Solution {
- // X=start, Y=end, D=distance for code clarity
- public int solution(int start, int end, int distance) {
- // write your code in Java SE 7
- int progress = start;
- int count = 0;
- while (progress < end) {
- progress = progress + distance;
- count++;
- }
- return count;
- }
- }
- progress = progress + distance;
- progress += distance;
- public class Solution {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement