1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组中重复的数据 [find-all-duplicates-in-an-array].html
2022-03-29 12:43:11 +08:00

38 lines
1.1 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>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,其中 <code>nums</code> 的所有整数都在范围 <code>[1, n]</code> 内,且每个整数出现 <strong>一次</strong><strong>两次</strong> 。请你找出所有出现 <strong>两次</strong> 的整数,并以数组形式返回。</p>
<p>你必须设计并实现一个时间复杂度为 <code>O(n)</code> 且仅使用常量额外空间的算法解决此问题。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [4,3,2,7,8,2,3,1]
<strong>输出:</strong>[2,3]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,1,2]
<strong>输出:</strong>[1]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [1]
<strong>输出:</strong>[]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= n</code></li>
<li><code>nums</code> 中的每个元素出现 <strong>一次</strong><strong>两次</strong></li>
</ul>