-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_number.py
More file actions
28 lines (28 loc) · 767 Bytes
/
Copy pathsingle_number.py
File metadata and controls
28 lines (28 loc) · 767 Bytes
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
class Solution:
def singleNumber(self, nums: List[int]) -> int:
d = {}
if len(nums) == 1:
return nums[0]
for i in nums:
if i in d:
count = d[i]
count += 1
d[i] = count
else:
d[i] = 1
for key,value in d.items():
if value == 1:
return key
class Solution:
def singleNumber(self, nums: List[int]) -> int:
d = {}
if len(nums) == 1:
return nums[0]
for i in nums:
if i in d:
count = d[i]
count += 1
d[i] = count
else:
d[i] = 1
return min(d.items(), key=lambda x: x[1])[0]