LeetCode 268 Missing Number

LeetCode 268 Missing Number Problem

Download Code
class Solution(object):
    # def missingNumber(self, nums):
    #     """
    #     :type nums: List[int]
    #     :rtype: int
    #     """
    #     n = len(nums)
    #     return (n ** 2 + n) / 2 - sum(nums)

    def missingNumber(self, nums):
        res = len(nums)
        for i, v in enumerate(nums):
            res ^= i
            res ^= v
        return res
    
    # def missingNumber(self, nums):
    #     nums.sort()
    #     left, right = 0, len(nums) - 1
    #     while left <= right:
    #         mid = (left + right) / 2
    #         if nums[mid] <= mid:
    #             left = mid + 1
    #         else:
    #             right = mid - 1
    #     return left
Download Missing Number.py

List of all Missing Number problems

Leetcode 268 Missing Number problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.