Skip to content

Commit e32fefe

Browse files
authored
Create 1526. Minimum Number of Increments on Subarrays to Form a Targ… (#921)
2 parents 56a8302 + afe88e5 commit e32fefe

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <vector>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
int minNumberOperations(vector<int>& target) {
7+
if (target.empty()) return 0;
8+
int n = target.size();
9+
long long ans = target[0];
10+
for (int i = 1; i < n; ++i) {
11+
if (target[i] > target[i - 1]) {
12+
ans += (target[i] - target[i - 1]);
13+
}
14+
}
15+
return (int)ans;
16+
}
17+
};

0 commit comments

Comments
 (0)