Construct Target Array With Multiple Sums LeetCode solution in Python
1# Runtime: 492 ms (Top 22.46%) | Memory: 20 MB (Top 17.02%)2class Solution:3def isPossible(self, target: List[int]) -> bool:4if len(target) == 1:5return target == [1]6res = sum(target)7heap = [-elem for elem in target]8heapify(heap)9while heap[0] < -1:10maximum = -heappop(heap)11res -= maximum1213if res == 1:14return True15x = maximum % res16if x == 0 or (x != 1 and x == maximum):17return False1819res += x20heappush(heap, -x)21return True