easy python solution

  • 0
    import sys
    class Solution(object):
        def thirdMax(self, nums):
            top = [-sys.maxint]*3
            for i in nums:
                if i > top[2]:
                    top = [top[1],top[2],i]
                elif top[2]>i> top[1]:
                    top = [top[1],i,top[2]]
                elif top[1]>i> top[0]:
                    top = [i,top[1],top[2]]
            return top[0] if top[0]!=-sys.maxint else top[2]

Log in to reply

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