We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 40876bb commit 8cc6bd3Copy full SHA for 8cc6bd3
C++/stone-game-vi.cpp
@@ -0,0 +1,19 @@
1
+// Time: O(nlogn)
2
+// Space: O(n)
3
+
4
+class Solution {
5
+public:
6
+ int stoneGameVI(vector<int>& aliceValues, vector<int>& bobValues) {
7
+ vector<vector<int>> sorted_vals;
8
+ vector<int> result(2);
9
+ for (int i = 0; i < size(aliceValues); ++i) {
10
+ sorted_vals.push_back({aliceValues[i] + bobValues[i],
11
+ aliceValues[i], bobValues[i]});
12
+ }
13
+ sort(begin(sorted_vals), end(sorted_vals), greater<vector<int>>());
14
+ for (int i = 0; i < size(sorted_vals); ++i) {
15
+ result[i % 2] += sorted_vals[i][1 + i % 2];
16
17
+ return (result[0] == result[1]) ? 0 : (result[0] > result[1]) ? 1 : -1;
18
19
+};
0 commit comments