Given a list of integers nums, read it from left to right and return the first value that appears for the second time.
If no value appears twice, return -1.
Example 1:
Input: nums = [3, 1, 4, 1, 3] Output: 1 Explanation: Reading from the left: 3, 1, 4, then 1 again. The second 1 (index 3) comes before the second 3 (index 4), so the answer is 1, although 3 showed up first.
Example 2:
Input: nums = [2, 7, 9] Output: -1 Explanation: Every value appears once, so nothing repeats.
Example 3:
Input: nums = [6, 6, 6, 6] Output: 6 Explanation: The second 6, at index 1, is already a repeat.
Constraints:
numshas at least one number.- Every number is between 0 and 109, so
-1always means that no value repeats.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
