题
思
最优策略就是每次都拿aliceValue+bobValue最高的。
这题很土味。
代码
class Solution {
public int stoneGameVI(int[] aliceValues, int[] bobValues) {
int aliceScore = 0, bobScore = 0;
int[][] value = new int[aliceValues.length][3];
for (int i = 0; i < value.length; i++) {
value[i][0] = aliceValues[i] + bobValues[i];
value[i][1] = aliceValues[i];
value[i][2] = bobValues[i];
}
Arrays.sort(value, (a, b) -> b[0] - a[0]);
for (int i = 0; i < value.length; i++) {
if (i % 2 == 0) {
aliceScore += value[i][1];
} else {
bobScore += value[i][2];
}
}
return aliceScore == bobScore ? 0 : (aliceScore > bobScore ? 1 : -1);
}
}