if len(nums)>=3: return nums[2] else:return nums[0] sol=Solution() print sol.thirdMax([1, 2])
Leetcode 数组:414 第三大的数 third-maximum-number 给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。 classSolution:defthirdMax(self, nums: List[int]) ->int: nums=list(set(nums)) MAX= float('-inf') SECEND_MAX= float('-inf')...
414. 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: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1. Example...