Skip to content

Commit 657f248

Browse files
authored
Create 1686-stone-game-vi.js
1 parent 81568f5 commit 657f248

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

1686-stone-game-vi.js

+25
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)