Skip to content
Open
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
66eea04
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 11, 2023
e662451
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 11, 2023
352d0fb
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 14, 2023
492890f
Merge branch 'TheAlgorithms:master' into Single-number-I
eukub Nov 14, 2023
ea22368
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 14, 2023
67859cc
Merge branch 'Single-number-I' of github.com:eukub/Python into Single…
eukub Nov 14, 2023
2fec97b
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 11, 2023
09a990b
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 11, 2023
66af9cb
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 14, 2023
56017b7
Algorithm solving problem "136. Single Number" from Leetcode (https:/…
eukub Nov 14, 2023
b91dbfc
Fix ignore venv in build_directory_md.py (#11156)
FishyGitHubUser Nov 16, 2023
f693cd9
adding a geometry module (#11138)
meg-1 Nov 24, 2023
9a3ddf1
Fix typo in knight_tour.py (#11173)
FishyGitHubUser Nov 25, 2023
826f64d
Typo deicmal -> decimal (#11169)
rahidzeynal Nov 25, 2023
8ecbc70
add graphs/ant_colony_optimization_algorithms.py (#11163)
Clarkzzzzz Nov 25, 2023
3c2925d
Bug fix combinations (#11158)
moaldeen Nov 25, 2023
f474f45
[pre-commit.ci] pre-commit autoupdate (#11154)
pre-commit-ci[bot] Nov 25, 2023
7922760
Create Spearman's rank correlation coefficient (#11155)
cyrixninja Nov 25, 2023
414f854
Added doctest to binary_search_tree.py (#11145)
Suyashd999 Nov 25, 2023
c36b5a7
Update levenshtein_distance.py (#11171)
pedram-mohajer Nov 26, 2023
9b8e185
Add doctest to is_safe function (#11183)
pedram-mohajer Nov 27, 2023
262c01f
[pre-commit.ci] pre-commit autoupdate (#11184)
pre-commit-ci[bot] Nov 27, 2023
0a89331
Create smallestRange.py (#11179)
pedram-mohajer Dec 1, 2023
daa4b92
Merge branch 'Single-number-I' of github.com:eukub/Python into Single…
eukub Dec 2, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions bit_manipulation/single_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Given a non-empty array of integers nums, every element
appears twice except for one. Find that single one

You must implement a solution with a linear runtime complexity
and use only constant extra space.

Reference: https://leetcode.com/problems/single-number/
"""


def single_number(nums: list) -> int:
"""
:param nums: A non-empty array of any integers nums,
every element appears twice except for one.
:return: element that appears only one time

Examples:
Example 1
>>> print(single_number([1, 3, 3, 2, 6, 2, 1]))
6

Example 2
>>> print(single_number([12, 1, 1, 7, 1, 12, 1]))
7

Example 3
>>> print(single_number([6]))
6
"""

result = 0
for el in nums:
result ^= el
return result


if __name__ == "__main__":
import doctest

doctest.testmod()