-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path414.py
More file actions
27 lines (27 loc) · 731 Bytes
/
Copy path414.py
File metadata and controls
27 lines (27 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def thirdMax(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
size = len(nums)
if size < 3:
return max(nums)
first = float('-inf')
second = float('-inf')
third = float('-inf')
for n in nums:
if first < n:
third = second
second = first
first = n
elif first == n:
continue
elif second < n:
third = second
second = n
elif second == n:
continue
elif third < n:
third = n
return third if third != float('-inf') else first