본문 바로가기

IT/알고리즘

[코딜리티] - Lesson 5. CountDiv

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