Class Solution
java.lang.Object
g0201_0300.s0287_find_the_duplicate_number.Solution
287 - Find the Duplicate Number.<p>Medium</p>
<p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the problem <strong>without</strong> modifying the array <code>nums</code> and uses only constant extra space.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,4,2,2]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [3,1,3,4,2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [1,1]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> nums = [1,1,2]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>nums.length == n + 1</code></li>
<li><code>1 <= nums[i] <= n</code></li>
<li>All the integers in <code>nums</code> appear only <strong>once</strong> except for <strong>precisely one integer</strong> which appears <strong>two or more</strong> times.</li>
</ul>
<p><strong>Follow up:</strong></p>
<ul>
<li>How can we prove that at least one duplicate number must exist in <code>nums</code>?</li>
<li>Can you solve the problem in linear runtime complexity?</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findDuplicate
public int findDuplicate(int[] nums)
-