Skip to content

Commit 316c961

Browse files
authored
Create maximum-points-after-enemy-battles.cpp
1 parent 194f6f7 commit 316c961

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// greedy
5+
class Solution {
6+
public:
7+
long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {
8+
const int mn = ranges::min(enemyEnergies);
9+
return currentEnergy >= mn ? ((currentEnergy - mn) + accumulate(cbegin(enemyEnergies), cend(enemyEnergies), 0ll)) / mn : 0;
10+
}
11+
};

0 commit comments

Comments
 (0)