FunctionRacerProblemsRace

Find the Duplicate Number

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

nums holds n + 1 numbers, each between 1 and n. Exactly one value is repeated (it may appear more than twice); every other value appears once or not at all.

Return the repeated value. Do not change nums.

Example 1

nums [1,3,4,2,2]
returns 2

2 appears twice.

Example 2

nums [3,3,3,3,3]
returns 3

Repeated many times.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems