-
[LeetCode] 1354. Construct Target Array With Multiple Sums알고리즘 2022. 6. 24. 17:55
import heapq class Solution: def isPossible(self, target: List[int]) -> bool: heapq._heapify_max(target) s = sum(target) while (target[0] != 1): sub = s- target[0] if (sub >= target[0] or sub == 0): return False iterNum = max( ((target[0]-1) // sub),1) temp = target[0] - (sub * iterNum) if (temp < 1): return False v = heapq._heapreplace_max(target, temp) s = sum(target) return True
'알고리즘' 카테고리의 다른 글
[LeetCode] 11. Container With Most Water (0) 2022.06.25 [Python] heapq maxheap 메서드 종류 및 사용 (0) 2022.06.24 [LeetCode] 90. Subsets II (0) 2022.06.22 [LeetCode] 438. Find All Anagrams in a String (0) 2022.06.21 Manacher's Algorithm [가장 긴 펠렌드롬 찾기] (0) 2022.06.20