728x90
SMALL
안녕하세요 남갯입니다.
public int solution(int A, int B, int K) {
// write your code in Java SE 8
if (K == 1 || (A == B && B == K)){
return B - A + 1;
}
int result = 0;
int mock = (A > K) ? (A / K) : 0;
int namugi = A % K;
if (namugi > 0 && B < K) {
mock += 1;
}
result = (B >= K) ? ((B - (K * mock)) / K) : 0;
if (namugi == 0) {
result++;
}
return result;
}
https://app.codility.com/demo/results/training35DBFU-83N/
728x90
LIST
'IT > 알고리즘' 카테고리의 다른 글
[코딜리티] - Lesson 7. Brackets (0) | 2019.09.03 |
---|---|
[코딜리티] - Lesson 6. Triangle (0) | 2019.09.02 |
[코딜리티] - Lesson 6. Distinct (0) | 2019.08.22 |
[코딜리티] - Lesson 5. GenomicRangeQuery (0) | 2019.08.20 |
[코딜리티] - Lesson 5. PassingCars (0) | 2019.08.19 |