Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 184af5a

Browse files
Update Solution.java
1 parent 2beadad commit 184af5a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎solution/0500-0599/0502.IPO/Solution.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ class Solution {
55
public int findMaximizedCapital(int k, int W, int[] Profits, int[] Capital) {
66
// 首先检查是否存在所有项目都可投资且初始资本 W >= max(Capital) 的情况。如果是,返回利润中前 k 个最大元素的和。
77
boolean speedUp = true;
8-
for (int c: Capital) if (W < c) speedUp = false;
8+
for (int c: Capital) if (W < c) speedUp = false;
99
if (speedUp) {
1010
PriorityQueue<Integer> heap = new PriorityQueue<>();
11-
for (int p: Profits) {
11+
for (int p: Profits) {
1212
heap.add(p);
1313
if (heap.size() > k) heap.poll();
1414
}
15-
for (int h: heap) W += h;
15+
for (int h: heap) W += h;
1616
return W;
1717
}
1818

1919
int idx;
2020
int n = Profits.length;
21-
for(int i = 0; i < Math.min(k, n); ++i) {
21+
for(int i = 0; i < Math.min(k, n); ++i) {
2222
idx = -1;
2323
// 找到获取利润最多的项目
24-
for(int j = 0; j < n; ++j) {
24+
for(int j = 0; j < n; ++j) {
2525
if (W >= Capital[j]) {
26-
if (idx == -1) idx = j;
26+
if (idx == -1) idx = j;
2727
else if (Profits[idx] < Profits[j]) idx = j;
2828
}
2929
}
3030
// 找不到合适的项目
31-
if(idx == -1) break;
31+
if(idx == -1) break;
3232
// 累计当前项目的利润到总利润中,并把当前项目标记为"不可用"(设置成最大整数)
3333
W += Profits[idx];
3434
Capital[idx] = Integer.MAX_VALUE;
3535
}
36-
return W;
36+
return W;
3737
}
38-
}
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /