forked from AishwaryaBarai/Leetcode-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path136. Single Number
40 lines (31 loc) · 865 Bytes
/
136. Single Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Solution:
def singleNumber(self, nums: List[int]) -> int:
dic = {}
pop = dic.pop
for i in nums:
if i not in dic:
dic[i] = None
else:
del (dic[i])
return(dic.popitem()[0])
class Solution:
def singleNumber(self, nums: List[int]) -> int:
x = Counter(nums)
for i in x:
if x[i] == 1:
return i
class Solution:
def singleNumber(self, nums: List[int]) -> int:
stack = []
for i in nums:
if i not in stack:
stack.append(i)
else:
stack.remove(i)
return stack[0]
class Solution:
def singleNumber(self, nums: List[int]) -> int:
a = 0
for i in nums:
a ^= i
return a