最近在学scala语言,scala代码如下:
import scala.collection.JavaConversions._
object Solution {
def solution(A: Int, B: Int, K: Int): Int = {
// write your code in Scala 2.10
var cnt: Int = 0
// let start element to be zero
if(A%K != 0) cnt -= K-A%K
// let end element to be zero too
if(B%K != 0) cnt -= B%K
cnt += B-A+1
if(cnt <= 0) 0
else cnt/K+cnt%K
}
}