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)/第三大的数 [third-maximum-number].html
2022-03-29 12:43:11 +08:00

40 lines
1.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个非空数组,返回此数组中 <strong>第三大的数</strong> 。如果不存在,则返回数组中最大的数。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>[3, 2, 1]
<strong>输出:</strong>1
<strong>解释:</strong>第三大的数是 1 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>[1, 2]
<strong>输出:</strong>2
<strong>解释:</strong>第三大的数不存在, 所以返回最大的数 2 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>[2, 2, 3, 1]
<strong>输出:</strong>1
<strong>解释:</strong>注意,要求返回第三大的数,是指在所有不同数字中排第三大的数。
此例中存在两个值为 2 的数,它们都排第二。在所有不同数字中排第三大的数为 1 。</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
</ul>
<p> </p>
<p><strong>进阶:</strong>你能设计一个时间复杂度 <code>O(n)</code> 的解决方案吗?</p>