Two solutions Bit Manipulation && Sum


  • 0

    Bit Manipulation

    class Solution(object):
        def missingNumber(self, nums):
            record = 0
            for num in nums:
                record |= 1 << num
    
            for i in xrange(len(nums) + 1):
                if not record & 1 << i:
                    return i
    

    Sum

    class Solution(object):
        def missingNumber(self, nums):
            return sum(range(len(nums) + 1)) - sum(nums)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.