Python Solution (self-explanatory)

  • 0


    class Solution(object):
        def thirdMax(self, nums):
            :type nums: List[int]
            :rtype: int
            a, b, c = float('-Inf'), float('-Inf'), float('-Inf')
            for n in nums:
                if n in (a, b, c): continue
                if n > a:
                    a, b, c = n, a, b
                if a > n > b:
                    a, b, c = a, n, b
                if b > n > c:
                    a, b, c = a, b, n
            return c if c != float('-Inf') else a

Log in to reply

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