Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 13, 2015 17:48
Show Gist options
  • Save stephen-maina/a8b17182c6e1a536cc5a to your computer and use it in GitHub Desktop.
Save stephen-maina/a8b17182c6e1a536cc5a to your computer and use it in GitHub Desktop.
CountDiv
class Solution {
public int solution(int A, int B, int K) {
// write your code in Java SE 8
int first=0;
int last=0;
if(A%K==0){
first=A/K;
}else{
first=(A-A%K+K)/K;
}
if(B%K==0){
last=B/K;
}else{
last=(B-B%K)/K;
}
return last-first+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment