1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public int giveGem(int[] gem, int[][] operations) { int max = 0, min = Integer.MAX_VALUE; for (int[] op : operations) { int x = op[0], y = op[1], val = gem[x] >> 1; gem[y] += val; gem[x] -= val; } for (int x : gem) { max = Math.max(max, x); min = Math.min(min, x); } return max - min; } }
|