Write a simple function to find duplicates in an array. What are the time and space complexities?
Implement find_duplicates(nums). Given a list of integers, return each value that appears at least twice exactly once, ordered by the position where its duplicate occurrence is first detected. Return an empty list when there are no duplicates.
Function signature: def find_duplicates(nums): Input is a list of integers, and output is a list of integers.
def find_duplicates(nums):