【leetcode❤python】 414. Third Maximum Number

#-*- coding: UTF-8 -*-
#l1 = ['1','3','2','3','2','1','1']
#l2 = sorted(sorted(set(l1),key=l1.index,reverse=False),reverse=True)
class Solution(object):
    def thirdMax(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if nums==[]:return []
        nums=sorted(sorted(set(nums),key=nums.index),reverse=True)
        if len(nums)>=3:
            return nums[2]
        else:return nums[0]

sol=Solution()
print sol.thirdMax([1, 2])

posted @ 2016-11-13 19:25  火金队长  阅读(251)  评论(0编辑  收藏  举报