Skip to content

Commit 3a750f0

Browse files
committed
2019-07-13
1 parent 27394bb commit 3a750f0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def thirdMax(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: int
6+
"""
7+
nums = list(set(nums))
8+
if len(nums) <= 2:
9+
return max(nums)
10+
11+
maxx = max(nums)
12+
maxx2 = nums[0]
13+
for num in nums:
14+
if num == maxx:
15+
continue
16+
maxx2 = max(num, maxx2)
17+
18+
res = nums[0]
19+
for num in nums:
20+
if num == maxx or num == maxx2:
21+
continue
22+
res = max(num, res)
23+
return res

0 commit comments

Comments
 (0)