Python Heap - Check duplicate using a seen set
We can either check duplicate using\n1- (done here) a seen set before pushing to heap\n2- checking if the top of heap is same as popped value, if so ignore it\n
We can either check duplicate using\n1- (done here) a seen set before pushing to heap\n2- checking if the top of heap is same as popped value, if so ignore it\n\n```\ndef nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:\n        heap = [1]\n        seen = set()\n        cnt = 1\n        while True:\n            cur = heapq.heappop(heap)\n            if cnt == n:\n                return cur\n            \n            for prime in primes:\n                new_super_ugly = cur * prime\n                if new_super_ugly not in seen:\n                    heapq.heappush(heap, new_super_ugly)\n                    seen.add(new_super_ugly)\n\n            cnt += 1\n```
[]