1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/寻找重复数 [find-the-duplicate-number].html

51 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个包含&nbsp;<code>n + 1</code> 个整数的数组&nbsp;<code>nums</code> ,其数字都在&nbsp;<code>[1, n]</code>&nbsp;范围内(包括 <code>1</code><code>n</code>),可知至少存在一个重复的整数。</p>
<p>假设 <code>nums</code> 只有 <strong>一个重复的整数</strong> ,返回&nbsp;<strong>这个重复的数</strong></p>
<p>你设计的解决方案必须 <strong>不修改</strong> 数组 <code>nums</code> 且只用常量级 <code>O(1)</code> 的额外空间。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,3,4,2,2]
<strong>输出:</strong>2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [3,1,3,4,2]
<strong>输出:</strong>3
</pre>
<p><strong>示例 3 :</strong></p>
<pre>
<strong>输入:</strong>nums = [3,3,3,3,3]
<strong>输出:</strong>3
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>nums.length == n + 1</code></li>
<li><code>1 &lt;= nums[i] &lt;= n</code></li>
<li><code>nums</code><strong>只有一个整数</strong> 出现 <strong>两次或多次</strong> ,其余整数均只出现 <strong>一次</strong></li>
</ul>
<p>&nbsp;</p>
<p><b>进阶:</b></p>
<ul>
<li>如何证明 <code>nums</code> 中至少存在一个重复的数字?</li>
<li>你可以设计一个线性级时间复杂度 <code>O(n)</code> 的解决方案吗?</li>
</ul>