leetcode 268. Missing Number python

xiaoxiao2021-02-28  15

给定一个包含从0,1,2,...,n中取出的n个不同数字的数组,找到数组中缺少的数字。

Example 1

Input: [3,0,1] Output: 2

Example 2

Input: [9,6,4,2,3,5,7,0,1] Output: 8 class Solution(object): def missingNumber(self, nums): """ :type nums: List[int] :rtype: int """ n = len(nums) return n*(n+1)/2 - sum(nums)
转载请注明原文地址: https://www.6miu.com/read-2650202.html

最新回复(0)