首页 > 代码库 > 414. Third Maximum Number
414. Third Maximum Number
https://leetcode.com/problems/third-maximum-number/#/description
class Solution(object): def thirdMax(self, nums): """ :type nums: List[int] :rtype: int """ # if len(nums) == 0: # return None # elif len(nums) < 3: # return max(nums) #else: v = [float(‘-inf‘), float(‘-inf‘), float(‘-inf‘)] for num in nums: if num not in v: if num > v[0]: v = [num, v[0],v[1]] elif num > v[1]: v = [v[0], num, v[1]] elif num > v[2]: v = [v[0], v[1], num] if float(‘-inf‘) in v: return max(nums) return v[2]
414. Third Maximum Number
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。