File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+ class Solution (object ):
3
+ def thirdMax (self , nums ):
4
+ """
5
+ :type nums: List[int]
6
+ :rtype: int
7
+ """
8
+ first_max = - sys .maxsize
9
+ second_max = - sys .maxsize
10
+ third_max = - sys .maxsize
11
+ for i in nums :
12
+ if (i > first_max ):
13
+ third_max = second_max
14
+ second_max = first_max
15
+ first_max = i
16
+ elif i == first_max :
17
+ pass
18
+ elif i > second_max :
19
+ third_max = second_max
20
+ second_max = i
21
+ elif i == second_max :
22
+ pass
23
+ elif i > third_max :
24
+ third_max = i
25
+ print (third_max ,second_max ,first_max )
26
+ if third_max == - sys .maxsize :
27
+ return first_max
28
+ else :
29
+ return third_max
30
+
31
+ sol = Solution ()
32
+ print (sol .thirdMax ([1 ,2 ]))
33
+ print (sol .thirdMax ([3 ,3 , 2 , 1 ]))
34
+ print (sol .thirdMax ([3 , 2 ,2 , 1 ]))
35
+ print (sol .thirdMax ([3 , 2 , 1 ]))
36
+
You can’t perform that action at this time.
0 commit comments