-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c419290
commit 957065e
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<h2><a href="https://leetcode.com/problems/find-the-duplicate-number">287. Find the Duplicate Number</a></h2><h3>Medium</h3><hr><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 using only constant extra space.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,3,4,2,2] | ||
<strong>Output:</strong> 2 | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [3,1,3,4,2] | ||
<strong>Output:</strong> 3 | ||
</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [3,3,3,3,3] | ||
<strong>Output:</strong> 3</pre> | ||
|
||
<p> </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> </p> | ||
<p><b>Follow up:</b></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> |