1class Solution:2def thirdMax(self, nums: List[int]) -> int:3nums_set = set(nums)4sorted_set = sorted(nums_set)5return sorted_set[-3] if len(nums_set) > 2 else sorted_set[-1]67# use set() to remove dups8# if len of nums after dups have been removed is at least 2, a third max val must exist9# if not, just return the max1011# you can do it in 1 line like this but then you have to call the same functions repeatedly12# return sorted(set(nums))[-3] if len(set(nums)) > 2 else sorted(set(nums))[-1]