Missing Number
Problem: Missing Number
We just calculate the sum of the numbers in the list and sum of 0 to n and the difference will be our answer.
Code in Python:
class Solution(object):
def missingNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
sum1, sum2 = 0, 0
for i in xrange(len(nums)):
sum1, sum2 = sum1+nums[i], sum2+(i+1)
return sum2-sum1