Skip to content

Latest commit

 

History

History
15 lines (13 loc) · 396 Bytes

P111. 丢失的数字.md

File metadata and controls

15 lines (13 loc) · 396 Bytes

给定一个包含 [0, n] 中 n 个数的数组 nums ,找出 [0, n] 这个范围内没有出现在数组中的那个数。

class Solution(object):
    def missingNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        missing = len(nums)

        for ind, num in enumerate(nums):
            missing ^= ind^num
        return missing