leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2673.cpp (344B)


0 class Solution {
1 public:
2 int minIncrements(int n, vector<int> &cost) const {
3 int res = 0;
4 for (int i = n / 2 - 1; i >= 0; i--) {
5 const int next = i << 1;
6 res += abs(cost[next + 1] - cost[next + 2]);
7 cost[i] += max(cost[next + 1], cost[next + 2]);
8 }
9 return res;
10 }
11 };