공부/2024 항해99코딩클럽
99클럽 3기 코테 스터디 23일차 TIL /[LeetCode] 502.IPO 자바 풀이
푸딩코딩
2024. 8. 13. 20:22
728x90
반응형
1. 오늘의 학습 문제
문제
https://leetcode.com/problems/ipo/
코드
class Solution {
public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {
int n = capital.length;
PriorityQueue<int[]> q1 = new PriorityQueue<>((a, b) -> a[0] - b[0]);
for (int i = 0; i < n; ++i) {
q1.offer(new int[] {capital[i], profits[i]});
}
PriorityQueue<Integer> q2 = new PriorityQueue<>((a, b) -> b - a);
while (k-- > 0) {
while (!q1.isEmpty() && q1.peek()[0] <= w) {
q2.offer(q1.poll()[1]);
}
if (q2.isEmpty()) {
break;
}
w += q2.poll();
}
return w;
}
}
#99클럽 #코딩테스트 준비 #개발자 취업 #항해99 #TIL
728x90
반응형