leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
2673.cpp (344B)
1 class Solution { 2 public: 3 int minIncrements(int n, vector<int> &cost) const { 4 int res = 0; 5 for (int i = n / 2 - 1; i >= 0; i--) { 6 const int next = i << 1; 7 res += abs(cost[next + 1] - cost[next + 2]); 8 cost[i] += max(cost[next + 1], cost[next + 2]); 9 } 10 return res; 11 } 12 };