Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Given an array of integers in which two elements appear exactly once and all other elements appear exactly twice, find the two elements that appear only once.
- For example, given the array [2, 4, 6, 8, 10, 2, 6, 10], return 4 and 8. The order does not matter.
- Follow-up: Can you do this in linear time and constant space?'''
- List = [2, 4, 6, 8, 10, 2, 6, 10]
- Hash = {}
- for el in List:
- if el in Hash:
- Hash[el] += 1
- else:
- Hash[el] = 1
- Result = []
- for k,v in Hash.items():
- if v==1:
- Result.append(k)
- print(Result)
Advertisement
Add Comment
Please, Sign In to add comment