Skip to content

Commit dab6450

Browse files
authored
Create stone-game-viii.cpp
1 parent 1e4360c commit dab6450

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

C++/stone-game-viii.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int stoneGameVIII(vector<int>& stones) {
7+
partial_sum(begin(stones), end(stones), begin(stones));
8+
return accumulate(next(rbegin(stones)), prev(rend(stones)), stones.back(),
9+
[](int curr, int x) { return max(curr, x - curr); });
10+
}
11+
};

0 commit comments

Comments
 (0)