Skip to content

Instantly share code, notes, and snippets.

@darrenfu
Created August 21, 2016 08:59
Show Gist options
  • Save darrenfu/ad2dd9677755f6158ea89751be346d7a to your computer and use it in GitHub Desktop.
Save darrenfu/ad2dd9677755f6158ea89751be346d7a to your computer and use it in GitHub Desktop.
Compute number of integers divisible by k in range [a..b].
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