2018-10-11 leetcode Missing Number Missing Number1234567class Solution(object): def missingNumber(self, nums): """ :type nums: List[int] :rtype: int """ return (set([x for x in xrange(len(nums) + 1)]) - set(nums)).pop() 12345678class Solution(object): def missingNumber(self, nums): """ :type nums: List[int] :rtype: int """ n = len(nums) return n * (n+1) / 2 - sum(nums) test code 1234In [135]: s = Solution(); t = s.missingNumber([9,6,4,2,3,5,7,0,1])In [136]: tOut[136]: 8 leet code Newer Find the Duplicate Number Older Kth Smallest Element in a Sorted Matrix