Here is another codility problem solution from the codility lessons (CountDiv-Compute number of integers divisible by k in range [a..b].) due to the copy rights I can't copy the content of the problem here so to view the problem description click here.
class Solution {
public int solution(int A, int B, int K) {
// write your code in Java SE 8
int count = 0;
int div1 = 0;
int div2 = 0;
div1 = A / K;
div2 = B / K;
count = div2 - div1;
if (A % K == 0) count++;
return count;
}
}
No comments:
Post a Comment