Write a function to reverse a string or find a duplicate element in an array.
For this task, implement the array version. Given a non-empty list of integers containing at least one repeated value, return the first value encountered whose second occurrence is found while scanning from left to right.
Input: a list of integers. Output: the duplicated integer.
def find_duplicate(nums):