-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/5-prefix_sums/count_div/
π¬Β Idea
- Aκ° Kλ‘ λλμ΄λ¨μ΄μ§μ§ μλλ€λ©΄ Bμμ Kλ₯Ό λλ κ°μμ Aλ₯Ό Kλ‘ λλ κ°μ λΉΌμ 리ν΄νκ³ , Aκ° Kλ‘ λλμ΄λ¨μ΄μ§λ€λ©΄ Bμμ Kλ₯Ό λλ κ°μμ Aλ₯Ό Kλ‘ λλ κ°μ 1μ λν΄μ 리ν΄νλ€.
π¬Β νμ΄
public func solution(A : Int, B : Int, K : Int) -> Int {
if A % K != 0 {
return (B / K) - (A / K)
} else {
return (B / K) - (A / K) + 1
}
}
μμμκ°
: 15λΆ
μκ° λ³΅μ‘λ
: O(1)
νκ°ν
: https://app.codility.com/demo/results/trainingMDRS56-ZFR/