Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
Example 1:
Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1.
Example 2:
Input: [1, 2] Output: 2 Explanation: The third maximum does not exist, so the maximum (2) is returned instead.
Example 3:
Input: [2, 2, 3, 1] Output: 1 Explanation: Note that the third maximum here means the third maximum distinct number. Both numbers with value 2 are both considered as second maximum.![]()
本文介绍了一种算法,该算法可以在O(n)的时间复杂度内找到一个整数数组中的第三大数值。如果不存在第三大数值,则返回数组中的最大值。文章通过三个示例详细解释了这一过程。

730

被折叠的 条评论
为什么被折叠?



