일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- GenerativeAI
- 코드업
- 구글퀵랩
- 생성형AI
- slidingwindow
- 릿코드
- stratascratch
- LeetCode
- 알고리즘
- 리트코드
- Python
- nlp
- Microsoft
- 파이썬알고리즘
- 파이썬
- GenAI
- Blazor
- two-pointer
- codeup
- 니트코드
- 투포인터
- 자연어처리
- Python3
- 파이썬기초100제
- SQL
- sql코테
- medium
- dfs
- 슬라이딩윈도우
- gcp
Archives
- Today
- Total
Tech for good
[Leetcode/Heap] 1464. Maximum Product of Two Elements in an Array 본문
IT/Computer Science
[Leetcode/Heap] 1464. Maximum Product of Two Elements in an Array
Diana Kang 2025. 3. 31. 23:05
class Solution:
def maxProduct(self, nums: List[int]) -> int:
# Convert to max-heap by pushing negative values
max_heap = [-num for num in nums]
heapq.heapify(max_heap)
# Pop the two largest values
first_max = -heapq.heappop(max_heap)
second_max = -heapq.heappop(max_heap)
return (first_max - 1) * (second_max - 1)
'IT > Computer Science' 카테고리의 다른 글
[Leetcode/Heap] 2558. Take Gifts From the Richest Pile (0) | 2025.04.04 |
---|---|
[Leetcode/Heap] 2099. Find Subsequence of Length K With the Largest Sum (0) | 2025.04.04 |
[Neetcode/Heap] K Closest Points to Origin (0) | 2025.03.31 |
[Leetcode/Tree] 872. Leaf-Similar Trees (0) | 2025.03.19 |
[Neetcode/Tree] Binary Tree Right Side View (0) | 2025.03.17 |