Download Third Maximum Number.py
class Solution(object): def thirdMax(self, nums): """ :type nums: List[int] :rtype: int """ import Queue pq = Queue.PriorityQueue(4) check = set() for n in nums: if n in check: continue pq.put(n) check.add(n) if len(check) > 3: check.remove(pq.get()) total = len(check) while total < 3 and total > 1: total -= 1 return pq.get()
Leetcode 414 Third Maximum Number problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.