Guest User

Untitled

a guest
Jun 30th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. '''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.
  2.  
  3. For example, given the array [2, 4, 6, 8, 10, 2, 6, 10], return 4 and 8. The order does not matter.
  4.  
  5. Follow-up: Can you do this in linear time and constant space?'''
  6.  
  7. List = [2, 4, 6, 8, 10, 2, 6, 10]
  8. Hash = {}
  9.  
  10. for el in List:
  11.     if el in Hash:
  12.         Hash[el] += 1
  13.     else:
  14.         Hash[el] = 1
  15.        
  16. Result = []
  17.  
  18. for k,v in Hash.items():
  19.     if v==1:
  20.         Result.append(k)
  21.        
  22. print(Result)
Advertisement
Add Comment
Please, Sign In to add comment