:type nums: List[int] :rtype: int
(self, nums)
| 1 | class 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() |