We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0e2e6ab commit 2fec97bCopy full SHA for 2fec97b
bit_manipulation/single_number.py
@@ -0,0 +1,23 @@
1
+"""
2
+ Given a non-empty array of integers nums, every element
3
+ appears twice except for one. Find that single one.
4
+
5
+ You must implement a solution with a linear runtime complexity
6
+ and use only constant extra space.
7
8
+ Reference: https://leetcode.com/problems/single-number/
9
10
11
12
+def single_number(nums: list) -> int:
13
+ """
14
+ :param nums: A non-empty array of any integers nums,
15
+ every element appears twice except for one.
16
+ :return: element that appears only one time
17
18
+ result = 0
19
20
+ for el in nums:
21
+ result ^= el
22
23
+ return result
0 commit comments