Skip to content

Commit f442fc8

Browse files
authored
Added Maximum Score From Removing Stones.java
1 parent 19a2abe commit f442fc8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int maximumScore(int a, int b, int c) {
3+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
4+
pq.addAll(Arrays.asList(a, b, c));
5+
int score = 0;
6+
while (pq.size() > 1) {
7+
int firstStoneCount = pq.remove();
8+
int secondStoneCount = pq.remove();
9+
if (firstStoneCount > 1) {
10+
pq.add(firstStoneCount - 1);
11+
}
12+
if (secondStoneCount > 1) {
13+
pq.add(secondStoneCount - 1);
14+
}
15+
score++;
16+
}
17+
return score;
18+
}
19+
}

0 commit comments

Comments
 (0)