414. Third Maximum Number

Posted Premiumlab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

414. Third Maximum Number

414. Third Maximum Number

414. Third Maximum Number

414. Third Maximum Number

Leetcode-414 Third Maximum Number

414. Third Maximum Number