MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / singleNumber

Method singleNumber

Python/single-number-ii.py:2–13  ·  view source on GitHub ↗
(self, nums: List[int])

Source from the content-addressed store, hash-verified

1class Solution:
2 def singleNumber(self, nums: List[int]) -> int:
3 dict1 = {} # Create hashtable
4 # Add counts into the hashtable
5 for x in nums:
6 if x not in dict1:
7 dict1[x] = 1
8 else:
9 dict1[x] += 1
10 # Select the single element
11 for ans, y in dict1.items():
12 if y == 1:
13 return ans
14
15# Or bitwise way
16class Solution:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected