有人能解释一下下面的陈述吗
if (dict.contains(sum-k)) count+= dict(sum-k)
dict(sum) += 1
实际代码:
object Solution {
def subarraySum(nums: Array[Int], k: Int): Int = {
if (nums isEmpty) return 0
val dict = scala.collection.mutable.Map[Int, Int]().withDefaultValue(0)
var count = 0
nums.scanLeft(0)(_+_).foreach { sum =>
**if (dict.contains(sum-k)) count+= dict(sum-k)
dict(sum) += 1**
}
count
}
}
暂无答案!
目前还没有任何答案,快来回答吧!