from typing import List


def find_duplicate(nums: List[int]) -> int:
    """
    Explanation:
    Given that there is exactly one extra, then we can find the value as
    the difference between the actual sum of the array and the sum of
    1 + 2 + .. + n.

    Time complexity: O(n)
    Space complexity: O(1)
    """
    n = len(nums) - 1
    total_sum = sum(range(1, n + 1))
    actual_sum = sum(nums)

    return actual_sum - total_sum