1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public int stoneGameVI(int[] a, int[] b) { int n = a.length; Integer[] index = new Integer[n]; for (int i = 0; i < n; i++) { index[i] = i; } Arrays.sort(index, (i, j) -> a[j] + b[j] - a[i] - b[i]); int diff = 0; for (int i = 0; i < n; i++) { diff += i % 2 == 0 ? a[index[i]] : -b[index[i]]; } return Integer.compare(diff, 0); } }
|