Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ddd7fc0

Browse files
Create Single Number.py
1 parent d2b72e7 commit ddd7fc0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
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
6+
a = 0
7+
for i in nums:
8+
a ^= i
9+
return a

0 commit comments

Comments
 (0)