1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-18 11:36:48 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 12:43:11 +08:00
parent 58bbdfd57c
commit 2b0511d272
10721 changed files with 8123 additions and 8119 deletions

View File

@@ -0,0 +1,39 @@
<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>