Created
August 21, 2016 08:59
-
-
Save darrenfu/ad2dd9677755f6158ea89751be346d7a to your computer and use it in GitHub Desktop.
Compute number of integers divisible by k in range [a..b].
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) { | |
return B == 0 ? 1 : (B / K - (A == 0 ? -1 : (A-1) / K )); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment