Created
April 13, 2015 17:48
-
-
Save stephen-maina/a8b17182c6e1a536cc5a to your computer and use it in GitHub Desktop.
CountDiv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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