Thursday, March 21, 2019

LeetCode 268. Missing Number

'''
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
'''
class Solution(object):
    #256ms, 12.6MB
    def missingNumber1(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        x = 0       
        s = sum(nums)       
        return (len(nums)+1)*len(nums)/2 - s

No comments:

Post a Comment