版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412944
思路
先计算不缺少元素的总和,减去当前的和,就是缺少的数
code
代码语言:javascript复制func missingNumber(nums []int) int {
total := 0
for _, v := range nums {
total = v
}
l := len(nums)
sum := l * (l 1) / 2
return sum - total
}