[Codility] Lession 5.2 CountDiv

Swift Solution:

public func solution(A : Int, _ B : Int, _ K : Int) -> Int{
  guard A <= B && B <= 2000000000 else { return 0 } 
  guard K >= 1 && K <= 2000000000 else { return 0 }  
 
  var result = 0  
  if (A % K == 0) { 
      result = ((B - A) / K) + 1 } 
  else{ 
      result = (B - (A - A % K)) / K }  
  return result}

你可能感兴趣的:([Codility] Lession 5.2 CountDiv)