Python solution use set


  • 1
    J
    class Solution(object):
        def thirdMax(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            s = set(nums)
            if len(s) < 3:
                return max(s)
            else:
                s.remove(max(s))
                s.remove(max(s))
                return max(s)
    

Log in to reply
 

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