Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.
class Solution: def thirdMax(self, nums: List[int]) -> int: n = list(set(nums)) if len(n) < 3: return max(n) return sorted(n)[-3]
Top comments (0)