Can you write a function to find duplicates in an array?
Implement find_duplicates(nums) to return a list containing each duplicated value exactly once, ordered by the index where its second occurrence appears. Return an empty list when all values are unique.
Input: a list of integers. Output: a list of duplicated integers.
def find_duplicates(nums):