Awesome python solution

  • 0
        def thirdMax(self, nums):
            v = 3 * [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[1], v[2] = num, v[1]
                    elif num > v[2]:
                        v[2] = num
            return v[0] if float('-inf') in v else v[2]

Log in to reply

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