【python3】leetcode 414. Third Maximum Numberr (easy)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/maotianyi941005/article/details/84994619

 414. Third Maximum Numberr (easy)

一、

返回第三大的数字,第一想法就是要排序

用了一个magic method 

class Solution:
    def thirdMax(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums = list(set(nums))
        if(len(nums) < 3):return max(nums)
        return sorted(nums).__getitem__(-3)

Runtime: 72 ms, faster than 8.82% of Python3 

猜你喜欢

转载自blog.csdn.net/maotianyi941005/article/details/84994619