Write code to find duplicates in an array.
Implement find_duplicates(nums) where nums is a list of integers. Return a list containing each duplicated value exactly once, ordered by the position where its second occurrence is encountered. Return an empty list when no value appears at least twice.
def find_duplicates(nums):