力扣每日一题
题目:1686. 石子游戏 VI

2024-02-02.png

日期:2024-02-02
用时:15 m 0 s
时间:103ms
内存:57.95MB
代码:

class Solution {
    public int stoneGameVI(int[] aliceValues, int[] bobValues) {
        int cnt = aliceValues.length;
        int[][] arrs = new int[cnt][2];
        for (int i = 0; i < cnt; i++) {
            arrs[i] = new int[]{aliceValues[i],bobValues[i]};
        }
        Arrays.sort(arrs,(a,b)->(b[0]+ b[1])-(a[0]+ a[1]));
        int sub = 0;
        for (int i = 0; i < cnt; i++) {
            sub+=i%2==0?arrs[i][0]:-arrs[i][1];
        }
        return sub == 0? 0 :sub / Math.abs(sub);
    }
}