Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding more tests to missing number algorithm #10394

Merged
merged 4 commits into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bit_manipulation/missing_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def find_missing_number(nums: list[int]) -> int:
Example:
>>> find_missing_number([0, 1, 3, 4])
2
>>> find_missing_number([4, 3, 1, 0])
2
>>> find_missing_number([-4, -3, -1, 0])
-2
>>> find_missing_number([-2, 2, 1, 3, 0])
-1
>>> find_missing_number([1, 3, 4, 5, 6])
2
>>> find_missing_number([6, 5, 4, 2, 1])
Expand All @@ -26,3 +32,9 @@ def find_missing_number(nums: list[int]) -> int:
missing_number ^= i ^ nums[i - low]

return missing_number


if __name__ == "__main__":
import doctest

doctest.testmod()