-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
33 lines (29 loc) · 908 Bytes
/
solution.py
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
28
29
30
31
32
33
class Solution(object):
def thirdMax(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
max_num = None
second_num = None
third_num = None
for num in nums:
if max_num == None:
max_num = num
else:
max_num = max(max_num, num)
for num in nums:
if num == max_num:
continue
elif second_num == None:
second_num = num
else:
second_num = max(second_num, num)
for num in nums:
if num == max_num or num == second_num:
continue
elif third_num == None:
third_num = num
else:
third_num = max(third_num, num)
return third_num if third_num != None else max_num