当我使用会更改数组或列表的东西时,通常会发生这种情况。例如这里:nums.drop(i)。我尝试调试,但它甚至看不到该行,如果您向我解释这种行为,我将不胜感激
def findDuplicates(nums: Array[Int]): List[Int] = {
nums.foldLeft(0)((accumValue, nextEl) => {
if (nums.tail.contains(nextEl)) {
accumValue
} else {
nums.drop(accumValue)
accumValue
}
})
nums.toList
}
Run Code Online (Sandbox Code Playgroud)