My 39ms python solution


  • 0
    K
    class Solution(object):
        def thirdMax(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            maximum = set()
            for num in nums:
                if len(maximum) < 3 or num > min(maximum):
                    maximum.add(num)
                    if len(maximum) > 3:
                        maximum.remove(min(maximum))
            if len(maximum) == 3:
                return min(maximum)
            else:
                return max(maximum)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.