01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第89题(顺位题号是414)。给定非空的整数数组,返回此数组中的第三个最大数字。如果不存在,则返回最大数量。时间复杂度必须在O(n)中。例如: 输入:[3,2,1] 输出:1 说明:第三个最大值为1。 输入:[1,2] 输出:2 说明:第三个最大值不存在,因此返...
}elseif(sz ==2){returnmax(nums[0], nums[1]); }inta = nums[0];intb =0;intc =0;boolsecond =false;// the second biggest number has foundboolthird =false;// the third biggest number has foundfor(inti =1; i < sz; i++){// cout<<a<<", "<<b<<", "<<c<<endl;if(a =...
Leetcode -- Third Maximum Number C语言 AC code O(N) Given integer array nums, return the third maximum number in this array. If the third maximum does not exist, return the maximum number. Example 1: Input: nums = [3,2,1] Output: 1 Explanation: The third maximum is 1. Example 2:...
Given a non-empty array of integers, return the third maximum number in thisarray. 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] Outpu...
[leetcode] 414. Third Maximum Number Description 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:
leetcode/problems/src/array/ThirdMaximumNumber.java/ Jump to Cannot retrieve contributors at this time 64 lines (55 sloc)1.65 KB RawBlame packagearray; /** * Created by gouthamvidyapradhan on 25/03/2017. Given a non-empty array of integers, return the third maximum number in this array. ...
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)。这里重复的数字视为一个。
Third Maximum Number Given anon-emptyarray of integers, return thethirdmaximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: 代码语言:javascript 复制 Input:[3,2,1]Output:1Explanation:The third maximum is1....
414. Third Maximum Number (第三大的数) 链接: https://leetcode-cn.com/problems/third-maximum-number/ 题目: 给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。 示例1: 输入: [3, 2, 1] ...
leetcode解题报告(15):Third Maximum Number 描述 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: