阅读背景:

python学习日志1

来源:互联网 

leetcode之ThirdmMaximumNumber的解法

class Solution(object):
    def thirdMax(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        l=[-2147483649,-2147483649,-2147483649]
        for n in nums:
            if n==l[0] or n==l[1] or n==l[2]:
                continue
            if n>l[2]:
                l[0]=l[1]
                l[1]=l[2]
                l[2]=n
            elif n>l[1]:
                l[0]=l[1]
                l[1]=n
            elif n>l[0]:
                l[0]=n
        if l[0]==l[1] or l[1]==l[2]:
            return l[2]
        elif l[0]==-2147483649:
            return l[2]
        else:
            return l[0]class Solu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: