Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class Solution { public int solution(int X, int Y, int D); }
  2.  
  3. Assume that:
  4. X, Y and D are integers within the range [1..1,000,000,000];
  5. X ≤ Y.
  6. Complexity:
  7. expected worst-case time complexity is O(1);
  8. expected worst-case space complexity is O(1).
  9.  
  10. class Solution {
  11. //X=start, Y=end, D=distance for code clarity
  12. public int solution(int start, int end, int distance) {
  13.  
  14. // write your code in Java SE 7
  15. int progress = start;
  16. int count=0;
  17. while(progress<end) {
  18. progress=progress+distance;
  19. count++;
  20. }
  21. return count;
  22. }
  23. }
  24.  
  25. public class Frog {
  26. public static int solution(int x, int y, int d) {
  27. return (int) Math.ceil((y - x) / (float)d);
  28. }
  29.  
  30. if ((y - x) % d == 0) {
  31. return (y - x) / d;
  32. }
  33. return (y - x) / d + 1;
  34.  
  35. return (y - x) / d + ((y - x) % d == 0 ? 0 : 1);
  36.  
  37. class Solution {
  38. // X=start, Y=end, D=distance for code clarity
  39. public int solution(int start, int end, int distance) {
  40.  
  41. // write your code in Java SE 7
  42. int progress = start;
  43. int count = 0;
  44. while (progress < end) {
  45. progress = progress + distance;
  46. count++;
  47. }
  48. return count;
  49. }
  50. }
  51.  
  52. progress = progress + distance;
  53.  
  54. progress += distance;
  55.  
  56. public class Solution {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement