AlgoLounge

Find the Duplicate Number

medium

You are given an array of integers nums containing n + 1 integers. Each integer in nums is in the range [1, n] inclusive.

Every integer appears exactly once, except for one integer which appears two or more times. Return the integer that appears more than once.

Examples

Example 1

Input:  nums = [1,2,3,2,2]
Output: 2

Example 2

Input:  nums = [1,2,3,4,4]
Output: 4

Constraints

  • 1 <= n <= 10000
  • nums.length == n + 1
  • 1 <= nums[i] <= n
TypeScript
Loading editor…
List of test cases (5)
Case 1
nums = [1,2,3,2,2]
Case 2
nums = [1,2,3,4,4]
Case 3
nums = [3,1,3,4,2]
Case 4
nums = [1,1]
Case 5
nums = [2,5,9,6,9,3,8,9,7,1,4]