일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- @Scheduled
- 프로젝트 구조
- 스프링 부트
- thymeleaf
- 스프링 메일
- pair
- 스프링 스케줄러
- vuejs #vue #js #프론트엔드 #nodejs #클라이언트사이드 #템플릿엔진
- HashMap
- 프로그래머스
- Collections
- maven
- C++
- list
- Spring Mail
- Spring Boot
- mybatis
- spring scheduler
- codility
- Spring
- java
- Dependency
- 코딩테스트
- GOF
- 의존성관리
- 스프링부트
- Arrays
- pom.xml
- 스프링
- springboot
- Today
- Total
Rooted In Develop
[Codility] Time Complexity - FrogJmp / Java 본문
1. 문제
A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.
Count the minimal number of jumps that the small frog must perform to reach its target.
Write a function:
class Solution { public int solution(int X, int Y, int D); }
that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.
For example, given:
X = 10 Y = 85 D = 30
the function should return 3, because the frog will be positioned as follows:
- after the first jump, at position 10 + 30 = 40
- after the second jump, at position 10 + 30 + 30 = 70
- after the third jump, at position 10 + 30 + 30 + 30 = 100
Write an efficient algorithm for the following assumptions:
- X, Y and D are integers within the range [1..1,000,000,000];
- X ≤ Y.
Copyright 2009–2020 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
2. 코드
class Solution {
public int solution(int X, int Y, int D) {
int dist = Y - X;
int jump = dist / D;
if(dist % D > 0)
jump++;
return jump;
}
}
'Algorithm Test > Java' 카테고리의 다른 글
[Codility] Time Complexity - TapeEquilibrium / Java (0) | 2020.06.14 |
---|---|
[Codility] Time Complexity - PermMissingElem / Java (0) | 2020.06.14 |
[Codility] Arrays - OddOccurrencesInArray / Java (0) | 2020.06.14 |
[Codility] Arrays - CyclicRotation / Java (0) | 2020.06.14 |
[Codility] Iterations - BinaryGap / Java (0) | 2020.06.14 |