We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 81568f5 commit 657f248Copy full SHA for 657f248
1686-stone-game-vi.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number[]} aliceValues
3
+ * @param {number[]} bobValues
4
+ * @return {number}
5
+ */
6
+var stoneGameVI = function(aliceValues, bobValues) {
7
+ let data = []
8
+ const length = aliceValues.length
9
+ for(let i = 0; i < length; i++) {
10
+ data.push([aliceValues[i] + bobValues[i], aliceValues[i], bobValues[i]])
11
+ }
12
+ data.sort((a, b) => a[0] - b[0])
13
+ data = data.reverse()
14
+
15
+ let aScore = 0
16
+ let bScore = 0
17
+ for(let i= 0; i<length; i++) {
18
+ if (i % 2 == 0)aScore += data[i][1]
19
+ else bScore += data[i][2]
20
21
22
+ if (aScore > bScore)return 1
23
+ else if (aScore == bScore)return 0
24
+ else return -1
25
+};
0 commit comments