fork download
  1.  
  2. A = [-15, -9, -6, -3, 1, 3, 6, 20]
  3.  
  4. nums = []
  5. while len(A) > 0:
  6. firstNum = max(abs(A[-1]), abs(A[0]))
  7. if not firstNum in nums:
  8. nums.append(firstNum)
  9. if -firstNum in A:
  10. A.remove(-firstNum)
  11. else:
  12. A.remove(firstNum)
  13. else:
  14. if -firstNum in A:
  15. A.remove(-firstNum)
  16. else:
  17. A.remove(firstNum)
  18. nums.reverse()
  19. print(nums)
  20.  
Success #stdin #stdout 0.01s 7072KB
stdin
Standard input is empty
stdout
[1, 3, 6, 9, 15, 20]