Third Max Number [Need help in optimization}

So, I am a newbie here. I have been using Python primarily because it is easy to understand and could help me improve my Problem solving. I have solved this question but would love to know a way to make it more efficient.

def thirdMax(self, nums: List[int]) -> int:
        if len(nums) < 3 or len(list(set(nums))) < 3:
            return max(nums)
        else:
            return sorted(list(set(nums)))[-3]
Comments (1)