通过万岁!!!
java代码
class Solution {
public int isWinner(int[] player1, int[] player2) {
int tenIdx1 = player1[0] == 10 ? 0 : -3;// 距离最开始要超过2
int tenIdx2 = player2[0] == 10 ? 0 : -3;
for (int i = 1; i < player1.length; i++) {
player1[0] += i - tenIdx1 <= 2 ? 2 * player1[i] : player1[i];
player2[0] += i - tenIdx2 <= 2 ? 2 * player2[i] : player2[i];
tenIdx1 = player1[i] == 10 ? i : tenIdx1;
tenIdx2 = player2[i] == 10 ? i : tenIdx2;
}
return player1[0] > player2[0] ? 1 : player1[0] == player2[0] ? 0 : 2;
}
}