class Solution:
def thirdMax(self, nums: List[int]) -> int:
x = y = z = -inf
for n in nums:
# if n > x:
# x, n = n, x
# if x > n > y:
# y, n = n, y
# if y > n > z:
# z = n
if n > x:
z, y, x = y, x, n
elif x > n > y:
z, y = y, n
elif y > n > z:
z = n
return x if z == -inf else zclass Solution:
def thirdMax(self, nums: List[int]) -> int:
d = {}
for n in nums:
d[n] = d.get(n, 0) + 1
return max(d) if len(d) < 3 else sorted(d)[-3]
# return x[-3] if len(x:=sorted(list(set(nums)))) > 2 else max(x)



