287. Find the Duplicate Number

Practice Find the Duplicate Number for free on NudgeCode: Medium, Linked List pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

The array nums has n + 1 integers, each in the range [1, n]. Exactly one value appears more than once (it may repeat several times). Return that value.

Try to solve it without modifying nums and with O(1) extra space.

Example

nums = [1,3,4,2,2]  ->  2

Constraints