Skip to content

Commit 457101f

Browse files
Create max_score_from_removing_stones.cpp
1 parent e8e0a19 commit 457101f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

max_score_from_removing_stones.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int maximumScore(int a, int b, int c) {
4+
priority_queue<int> maxHeap;
5+
6+
maxHeap.push(a);
7+
maxHeap.push(b);
8+
maxHeap.push(c);
9+
int score = 0;
10+
11+
while(maxHeap.size() > 1) {
12+
auto first = maxHeap.top();
13+
maxHeap.pop();
14+
15+
auto second = maxHeap.top();
16+
maxHeap.pop();
17+
18+
if(first > 0 and second > 0) {
19+
score++;
20+
maxHeap.push(first - 1);
21+
maxHeap.push(second - 1);
22+
}
23+
}
24+
25+
return score;
26+
}
27+
};

0 commit comments

Comments
 (0)