1. 程式人生 > >【python3】leetcode 414. Third Maximum Numberr (easy)

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

 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