Add missing number algorithm (#9203)

* Added missing_number algorithm using bit manipulation

* Update bit_manipulation/missing_number.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Shreya Bhalgat 2023-10-01 16:58:20 +05:30 committed by GitHub
parent eaa87bd791
commit cfabd91a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,21 @@
def find_missing_number(nums: list[int]) -> int:
"""
Finds the missing number in a list of consecutive integers.
Args:
nums: A list of integers.
Returns:
The missing number.
Example:
>>> find_missing_number([0, 1, 3, 4])
2
"""
n = len(nums)
missing_number = n
for i in range(n):
missing_number ^= i ^ nums[i]
return missing_number