1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public int giveGem(int[] gem, int[][] operations) { for (int[] operation : operations) { int fromIndex = operation[0], toIndex = operation[1]; int count = gem[fromIndex] / 2; gem[fromIndex] -= count; gem[toIndex] += count; }
int minCount = Integer.MAX_VALUE, maxCount = Integer.MIN_VALUE; for (int count : gem) { minCount = Math.min(minCount, count); maxCount = Math.max(maxCount, count); } return maxCount - minCount; } }
|