MCPcopy
hub / github.com/qiyuangong/leetcode / thirdMax

Method thirdMax

python/414_Third_Maximum_Number.py:2–20  ·  view source on GitHub ↗

:type nums: List[int] :rtype: int

(self, nums)

Source from the content-addressed store, hash-verified

1class Solution(object):
2 def thirdMax(self, nums):
3 """
4 :type nums: List[int]
5 :rtype: int
6 """
7 import Queue
8 pq = Queue.PriorityQueue(4)
9 check = set()
10 for n in nums:
11 if n in check:
12 continue
13 pq.put(n)
14 check.add(n)
15 if len(check) > 3:
16 check.remove(pq.get())
17 total = len(check)
18 while total < 3 and total > 1:
19 total -= 1
20 return pq.get()

Callers

nothing calls this directly

Calls 4

putMethod · 0.45
addMethod · 0.45
removeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected