Skip to content

Commit 452ac8f

Browse files
authoredMay 12, 2021
Update Single Number.py
1 parent 703ea5d commit 452ac8f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed
 

‎Arrays/Easy/Single Number.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
class Solution:
22
def singleNumber(self, nums: List[int]) -> int:
3+
#hashmap
4+
#math -> 2 * (a+b+c) - (a+a+b+b+c) = c
5+
#bitmasking -> a^0 = a and a^a = 0; a^b^a = a^a^b = 0^b = b
36
a = 0
47
for i in nums:
58
a ^= i

0 commit comments

Comments
 (0)
Please sign in to comment.