Leetcode - 268. Missing Number
Leetcode - 268. Missing Number
- Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Solution
1
2
3
4
5
6
7
8
9
10
11
func missingNumber(nums []int) int {
ln := len(nums)
sumTotal := (ln*(ln+1))/2
numSum := 0
for _, num := range nums{
numSum+=num
}
return sumTotal-numSum
}
This post is licensed under CC BY 4.0 by the author.