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.
Using math wikipedia to calculate the sum of the first consecutive integers:
class Solution: def missingNumber(self, nums: list[int]) -> int: length = len(nums) math_sum = (length * (length+1)) // 2 missing = math_sum - sum(nums) return missing
There was an error while loading. Please reload this page.