1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public int minIncrements(int n, int[] cost) {
int minIncrements = 0;
for (int i = cost.length / 2 - 1; i >= 0; i--) { minIncrements += Math.abs(cost[i * 2 + 1] - cost[i * 2 + 2]); cost[i] += Math.max(cost[i * 2 + 1], cost[i * 2 + 2]); }
return minIncrements; } }
|
References
2673. Make Costs of Paths Equal in a Binary Tree