Code
时间复杂度:O(N)
空间复杂度:O(1)
class Solution:
def thirdMax(self, nums: List[int]) -> int:
l = [-2**31-1, -2**31-1, -2**31-1]
for i in nums:
if i > l[0]:
l[2] = l[1]
l[1] = l[0]
l[0] = i
elif l[0] > i and i > l[1]:
l[2] = l[1]
l[1] = i
elif l[1] > i and i > l[2]:
l[2] = i
return l[0] if l[2] == -2**31-1 else l[2]