Skip to content

Commit 57e735b

Browse files
committed
Solved leetcode 502
1 parent df3e5f4 commit 57e735b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

502/502.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:
3+
4+
capHeap = []
5+
profHeap = []
6+
for i in range(len(profits)):
7+
capHeap.append((capital[i], profits[i]))
8+
9+
heapify(capHeap)
10+
11+
while(k > 0):
12+
while(capHeap and capHeap[0][0] <= w):
13+
pair = heappop(capHeap)
14+
heappush(profHeap, (-1 * pair[1], pair[0]))
15+
16+
if(len(profHeap) == 0):
17+
break
18+
currProfPair = heappop(profHeap)
19+
w += currProfPair[0] * -1
20+
k -= 1
21+
22+
23+
return w
24+
25+

0 commit comments

Comments
 (0)