|
| 1 | +<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> |
| 2 | + |
| 3 | +<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p> |
| 4 | + |
| 5 | +<p>You must solve the problem <strong>without</strong> modifying the array <code>nums</code> and using only constant extra space.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> nums = [1,3,4,2,2] |
| 12 | +<strong>Output:</strong> 2 |
| 13 | +</pre> |
| 14 | + |
| 15 | +<p><strong class="example">Example 2:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> nums = [3,1,3,4,2] |
| 19 | +<strong>Output:</strong> 3 |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 3:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> nums = [3,3,3,3,3] |
| 26 | +<strong>Output:</strong> 3</pre> |
| 27 | + |
| 28 | +<p> </p> |
| 29 | +<p><strong>Constraints:</strong></p> |
| 30 | + |
| 31 | +<ul> |
| 32 | + <li><code>1 <= n <= 10<sup>5</sup></code></li> |
| 33 | + <li><code>nums.length == n + 1</code></li> |
| 34 | + <li><code>1 <= nums[i] <= n</code></li> |
| 35 | + <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> |
| 36 | +</ul> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><b>Follow up:</b></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li>How can we prove that at least one duplicate number must exist in <code>nums</code>?</li> |
| 43 | + <li>Can you solve the problem in linear runtime complexity?</li> |
| 44 | +</ul> |
0 commit comments